gelfx v0.1.0 Gelfx View Source
A logger backend for Elixir applications using Logger
and Graylog based on GELF (Graylog extended logging format).
Usage
Add Gelfx to your application by adding {:gelfx, "~> 0.1.0"}
to your list of dependencies in mix.exs
:
def deps do
[
{:gelfx, "~> 0.1.0"}
]
end
And adding it to your :logger
configuration in config.exs
:
config :logger,
backends: [
:console,
Gelfx
]
Since GELF relies on json to encode the payload Gelfx will need a JSON library. By default Gelfx will use Jason which needs to be added to your deps in mix.exs:
{:jason, "~> 1.0"}
Options
Besides :level
, :format
and :metadata
, which are advised by Logger Gelfx supports:
:protocol
- either:tcp
or:udp
,:http
is not jet supported, defaults to :tcp:format
- defaults to "$message":host
- hostname of the server running the GELF endpoint:hostname
- used for the "host" field in the GELF message, defaults to the hostname returned by:inet.gethostname()
:json_library
- json library to use, has to implement aencode!/1
:port
- port on which the graylog server receives GELF messages:compression
- either:gzip
or:zlib
can be set and will be used for package compression when UDP is used as protocol
Message Format
The GELF message format version implemented by this library is 1.1
docs.
Messages can include a short_message
and a full_message
, Gelfx will use the first line of each log message for the short_message
and will place the whole message in the full_message
field.
Metadata will be included in the message using the additional field
syntax.
The Keys of the metadata entries have to match ^\_?[\w\.\-]*$
with keys missing an leading underscore are automatically prepended with one.
Key collisions are NOT prevented by Gelfx, additionally the keys id
and _id
are automatically omitted due to the GELF spec.
Levels
Graylog relies on the syslog definitions for logging levels. Gelfx maps the Elixir levels as follows:
Elixir | Sysylog | GELF - Selector |
---|---|---|
Emergency | 0 | |
Alert | 1 | |
Critical | 2 | |
:error | Error | 3 |
:warn | Warning | 4 |
Notice | 5 | |
:info | Informational | 6 |
:debug | Debug | 7 |
Link to this section Summary
Functions
Callback implementation for c::gen_event.handle_call/2
Callback implementation for c::gen_event.handle_event/2
Callback implementation for c::gen_event.handle_info/2
Callback implementation for c::gen_event.init/1
Link to this section Functions
chunk(binary, chunk_length, sequence_number \\ 0) View Source
encode(log_entry, state) View Source
flush(socket) View Source
handle_call(arg1, state) View Source
Callback implementation for c::gen_event.handle_call/2
.
handle_event(event, state) View Source
Callback implementation for c::gen_event.handle_event/2
.
handle_info(msg, state) View Source
Callback implementation for c::gen_event.handle_info/2
.
init(arg1) View Source
Callback implementation for c::gen_event.init/1
.