Documentation ¶
Overview ¶
Package sparki provides a client for sending logs to Loki with or without the use of the Zap logging framework.
For basic information on using this package, see README.md
Index ¶
- type ClientOption
- func WithClientHeaders(h http.Header) ClientOption
- func WithClientMaxPayloadAge(d time.Duration) ClientOption
- func WithClientMaxPayloadLength(logLines int) ClientOption
- func WithClientPushWorkers(numWorkers int) ClientOption
- func WithClientRetryLimit(limit int) ClientOption
- func WithClientTransport(t http.RoundTripper) ClientOption
- type Core
- type CoreOption
- type FieldFormatter
- type Label
- type PushClient
- type StreamClient
- type StreamOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientOption ¶
type ClientOption func(*opts)
ClientOption is used to configure a PushClient in NewPushClient See the With* functions for the available options.
func WithClientHeaders ¶
func WithClientHeaders(h http.Header) ClientOption
WithClientHeaders allows you to specify HTTP headers that should be added to any requests to Loki. This is potentially useful for Authorization purposes.
func WithClientMaxPayloadAge ¶
func WithClientMaxPayloadAge(d time.Duration) ClientOption
WithClientMaxPayloadAge specifies the maximum amount of t that may pass before a given stream must be committed to Loki. Note that logs may be sent to loki more frequently (requested sync or maxPayloadLength).
func WithClientMaxPayloadLength ¶
func WithClientMaxPayloadLength(logLines int) ClientOption
WithClientMaxPayloadLength specifies the number of log lines that can be added to a stream before it must be committed to Loki. Note that logs may be sent to loki before this threshold is hit (requested sync or maxPayloadAge).
func WithClientPushWorkers ¶
func WithClientPushWorkers(numWorkers int) ClientOption
WithClientPushWorkers sets the number of go routines created to send HTTP requests to Loki. The default is 6 workers.
func WithClientRetryLimit ¶
func WithClientRetryLimit(limit int) ClientOption
WithClientRetryLimit controls how many times logs that fail will be retried. Backoff period after a failure is exponential. PushClient gives up on logs after the limit is passed. Logs are lost at this point.
func WithClientTransport ¶
func WithClientTransport(t http.RoundTripper) ClientOption
WithClientTransport allows you to specify a custom HTTP transport that should be used when communicating with Loki.
type Core ¶
type Core struct { zapcore.LevelEnabler // contains filtered or unexported fields }
func NewCore ¶
func NewCore(sc *StreamClient, opts ...CoreOption) *Core
NewCore creates a zapcore that logs to a given StreamClient. Use any number of CoreOption (from WithCore*) to configure the Core.
func (*Core) Check ¶
func (s *Core) Check(entry zapcore.Entry, checked *zapcore.CheckedEntry) *zapcore.CheckedEntry
type CoreOption ¶
type CoreOption func(*coreOpts)
CoreOption can be passed to NewCore to configure the zap core
func WithCoreCaller ¶
func WithCoreCaller(includeCaller bool) CoreOption
WithCoreCaller specifies whether to add caller information to the log message as a field if zap provides the information
func WithCoreFieldFormatter ¶
func WithCoreFieldFormatter(formatter FieldFormatter) CoreOption
WithCoreFieldFormatter allows a function that is responsible for combining the log message and the fields into a single string to be specified. The default field formatter separates the message and the field list with "::" and lists the fields and their values, separated by spaces. E.g. My message :: level="error" field1="a" field2="b"
func WithCoreLevel ¶
func WithCoreLevel(level zapcore.Level) CoreOption
WithCoreLevel specifies the log level. The default is INFO or higher.
type FieldFormatter ¶
FieldFormatter takes a log message and its corresponding fields and returns a string with the fields and message combined somehow.
type Label ¶
Label associates a label name with a value. One or more labels uniquely identify a stream of messages in Loki. For best practices regarding labels in Loki, see: https://grafana.com/docs/loki/latest/best-practices/
type PushClient ¶
type PushClient struct {
// contains filtered or unexported fields
}
PushClient is used for sending log lines to Loki. Use NewPushClient to create a new PushClient. Before the application terminates, call Close to ensure all logs are sent. PushClient is safe for concurrent use.
func NewPushClient ¶
func NewPushClient(endpoint string, opts ...ClientOption) *PushClient
NewPushClient creates a new PushClient to send logs to endpoint with the specified Options The endpoint should be the Loki api route /loki/api/v1/push
func (*PushClient) Close ¶
func (l *PushClient) Close() error
Close will shut down all open streams, sending their logs to Loki in the process. This will block until all streams have terminated cleanly. The PushClient cannot be used again.
func (*PushClient) NewStream ¶
func (l *PushClient) NewStream(labels []Label, opts ...StreamOption) *StreamClient
NewStream creates a new stream with a given set of labels and returns a new StreamClient to write to the stream.
type StreamClient ¶
type StreamClient struct {
// contains filtered or unexported fields
}
StreamClient can write to a stream of a PushClient. Create one using the PushClient.NewStream method.
func (*StreamClient) Close ¶
func (sc *StreamClient) Close() error
Close instructs the stream to close and then flush itself. This does not block, so messages will be flushed in the background.
func (*StreamClient) Log ¶
func (sc *StreamClient) Log(t time.Time, message string) error
Log writes a message and its timestamp to the stream. Logs are buffered, so it may be some time (depending on the configuration) before it appears in Loki. This will block only if the underlying channel's buffer is full.
func (*StreamClient) Sync ¶
func (sc *StreamClient) Sync() error
Sync instructs PushClient to flush the stream to Loki. This will block until the logs have either been sent to loki or the push request has failed (in which case, the chunk will be retried in the background)
func (*StreamClient) SyncNoWait ¶
func (sc *StreamClient) SyncNoWait() error
SyncNoWait is similar to Sync, except that it will not block at all.
type StreamOption ¶
type StreamOption func(o *streamOpts)
StreamOption can be passed to NewStream to configure an individual stream.
func WithStreamMaxPayloadAge ¶
func WithStreamMaxPayloadAge(age time.Duration) StreamOption
WithStreamMaxPayloadAge is like WithClientMaxPayloadAge, except that it only applies to a single stream.
func WithStreamMaxPayloadLength ¶
func WithStreamMaxPayloadLength(limit int) StreamOption
WithStreamMaxPayloadLength is like WithClientMaxPayloadLength, except that it only applies to a single stream