This library allows logging to LogDNA from Logrus, optionally configuring everything using Logrus Mate.
This works for me, but is currently a work in progress.
Check out the example/
subdirectory for a simple example.
You can create hook manually, New
method or using Logrus Mate.
For HOCON configuration provider (the default), add a hook like this:
your-logger {
...
hooks {
logdna {
api-key = "your-ingestion-key-here"
app = "myapp"
json = true
}
...
}
...
}
The supported options are:
api-key
: ingestion key, mandatoryhostname
: hostname override, if not specified will useos.Hostname()
mac
: host MAC address, not sent if empty, no autodetection for nowip
: host IP address, dittoapp
: app identifier, for LogDNA to filterenv
: environment identifier, for LogDNA to filtersize
: buffer size, in entries, defaults to 4096flush
: flush interval, defaults to 10 secondsqsize
: buffered channel sizedrop
: whenever hook's allowed to drop messages (if buffer's full etc). Logging will block if this is false and there are size+qsize entries waiting to be sent.json
: how to send structured log fields. Will format line as JSON if set to true (using"message"
key for log message), or pass fields asmeta
if not.text-format
: whenever to also include structured logging data in the message. Default to false, enabling will append key-value pairs to the message texts, so they'll be immediately visible.url
allows to override the ignestion endpoint URL (e.g. for testing)
With New
method and Config
struct you have a little more flexibility,
as you can specify any MessageFormatter
rather than just text-format
.
As the logging is asynchronous, error handling is limited.
If drop
is set to true, you can lose messages on outages.
If drop
is false, program may panic at shutdown, or buffer size
may grow past the size
limit.
Also, to give the hooks chance flush before the program exits,
don't forget to add defer logrus.Exit(0)
to your main
.
Suggestions (and pull requests) are welcomed.