GELF Logger v0.10.0 Logger.Backends.Gelf View Source
GELF Logger Backend
GelfLogger
A logger backend that will generate Graylog Extended Log Format messages. The current version only supports UDP messages.
Configuration
In the config.exs, add gelf_logger as a backend like this:
config :logger,
backends: [:console, {Logger.Backends.Gelf, :gelf_logger}]
In addition, you'll need to pass in some configuration items to the backend itself:
config :logger, :gelf_logger,
host: "127.0.0.1",
port: 12201,
format: "$message",
application: "myapp",
compression: :gzip, # Defaults to :gzip, also accepts :zlib or :raw
metadata: [:request_id, :function, :module, :file, :line],
hostname: "hostname-override",
json_encoder: Poison,
tags: [
list: "of",
extra: "tags"
]
In addition, if you want to use your custom metadata formatter as a "callback", you'll need to add below configuration entry:
format: {Module, :function}
Please bear in mind that your formating function MUST return a tuple in following
format: {level, message, timestamp, metadata}
In addition to the backend configuration, you might want to check the
Logger configuration for other
options that might be important for your particular environment. In
particular, modifying the :utc_log
setting might be necessary
depending on your server configuration.
This backend supports metadata: :all
.
Note on the JSON encoder:
Currently, the logger defaults to Poison but it can be switched out for any module that has an encode!/1 function.
Usage
Just use Logger as normal.
Improvements
- [x] Tests
- [ ] TCP Support
- [x] Options for compression (none, zlib)
- [x] Send timestamp instead of relying on the Graylog server to set it
- [x] Find a better way of pulling the hostname
And probably many more. This is only out here because it might be useful to someone in its current state. Pull requests are always welcome.
Notes
Credit where credit is due, this would not exist without protofy/erl_graylog_sender.
Link to this section Summary
Functions
Callback implementation for :gen_event.code_change/3
.
Callback implementation for :gen_event.handle_call/2
.
Callback implementation for :gen_event.handle_event/2
.
Callback implementation for :gen_event.handle_info/2
.
Callback implementation for :gen_event.init/1
.
Callback implementation for :gen_event.terminate/2
.
Link to this section Functions
Callback implementation for :gen_event.code_change/3
.
Callback implementation for :gen_event.handle_call/2
.
Callback implementation for :gen_event.handle_event/2
.
Callback implementation for :gen_event.handle_info/2
.
Callback implementation for :gen_event.init/1
.
Callback implementation for :gen_event.terminate/2
.