This repository is a mirror of a private GitLab instance. All changes will be overwritten.
This hook allows logging with logrus to Loki. Logs are sent in logfmt format.
go get github.com/magnetde/loki
package main
import (
log "github.com/sirupsen/logrus"
"github.com/magnetde/loki"
)
func main() {
// NewHook(url, ...options)
hook := loki.NewHook("http://localhost:3200", loki.WithName("my-go-binary"), loki.WithMinLevel(log.InfoLevel))
defer hook.Close()
log.AddHook(hook)
// ...
}
{name="my-go-binary"} | logfmt | level =~ "warning|error|fatal|panic"
This displays all log entries of the application, with a severity of at least "warning".
The call depends on the Formatter
.
WithName(string)
:
This adds the additional label "name" to all log entries sent to loki. It is the only additional label, that is added to the log message if the default logger is used.WithLabel(string, interface{})
:
Similar toWithName
, this adds an additional label to all log entries sent to loki.WithLabelsEnabled(...Label)
:
Send additional attributes of the entry as labels. By default, only the name attribute is sent.
Available labels:- labels added with
WithName
orWithLabel
are always added to log entires FieldsLabel
: add all extra fields as labels (Entry.Data
)TimeLabel
: add the time as a label (Entry.Time
)LevelLabel
: add the log level as a label (Entry.Level
)CallerLabel
: add the caller with format"[file]:[line]:[function]"
(Entry.Caller
)MessageLabel
: add the message as a label (Entry.Message
)
- labels added with
WithFormatter(logrus.Formatter)
:
By default, theTextFormatter
with disabled colors and disabled timestamp is used. Additional, it formats the caller in format("file:line:func()", "")
(empty file value).WithRemoveColors(bool)
:
Remove ANSI colors from the serialized log entry. This only works with the default formatter.WithMinLevel(logrus.Level)
:
Minimum level for log entries. All entries that have a lower severity are ignored.WithBatchInterval(time.Duration)
:
Batch interval. If this interval has been reached since the last sending, all log entries collected so far will be sent (default: 10 seconds).WithBatchSize(int)
:
Maximum batch size. If the number of collected log entries is exceeded, all collected entries will be sent (default: 1000).WithSynchronous(bool)
:
By default (async mode), log entries are processed in a separate Go routine. If synchronous sending is used, batch interval and size are ignored.WithSuppressErrors(bool)
:
Errors at asynchronous mode are logged to the console. This disables the logging of errors. Ignored at synchronous mode.