gelato v0.3.0 Gelato View Source
Gelato
is a opinionated logger backend
helper library to log events with telemetry
attached.
It is to be configured in config.exs
in the following way:
config :gelato,
uri: "http://127.0.0.1:9200",
events: [:app, :lib],
handler: :elastic
config :logger,
backends: [Gelato.Logger.Backend],
level: :debug
and might be used normally as a usual logger backend
Logger.info "users", name: "John", reference: "U-123456789"
Basically, it logs the payload with the telemetry attached to the configured ElasticSearch instance. The telemetry includes some process information by default, besides monotonic time and some additional parameters.
The process info data might be altered or switched off by passing :process_info
keyword parameter in call to Logger.log/3
. true
value (default) would
collect and store the current process info; any other value would be passed through
as is.
level
parameter is one of:debug | :info | :warn | :error
message
is mapped to ElasticSearch index when passed; possible values must be configured inconfig.exs
file in the list of telemetry eventspayload
is a keyword list to be passed to Elastic
Also it supports benchmarking with Elixir.Gelato.bench/4
. The latter will
execute the block passed to the function, surrounded with two calls to
Logger.log/3
to collect some additional info about this particular
block execution.
By default all the logger methods would attach process_info
to the events
sent to Elastic to alter / discard this pass process_info: SOMETHING
to
the call to all the exported functions’ payload. Unless SOMETHING
is true
,
this value will be used instead of real process info.
Link to this section Summary
Functions
Similar to Logger.log/3
but accepts a block.
Defines a function that delegates to another module and wraps the delegated call
into Gelato.bench/4
. Similar to Kernel.defdelegate/2
.
Link to this section Functions
bench(level, tag \\ nil, entity, payload_and_do_block)
View Source (macro)bench( level :: Logger.level(), tag :: atom(), entity :: entity(), payload_and_do_block :: keyword() ) :: any()
Similar to Logger.log/3
but accepts a block.
The block will be executed, surrounded by calls to log
and the
telemetry data will be accumulated in the latter call.
Defines a function that delegates to another module and wraps the delegated call
into Gelato.bench/4
. Similar to Kernel.defdelegate/2
.
Functions defined with defdelegatelog/2
are public and can be invoked from
outside the module they’re defined in, as if they were defined using def/2
.
Options
:to
— the module to dispatch to.:as
— the function to call on the target given in:to
. This parameter is optional and defaults to the name being delegated (fun
).:level
— the level to be used for wrapping logging, default:info
:tag
— the tag to be used as an index in the target Elastic call. Default:"default"
.:entity
— additional key to simplify search in Elastic logs. Usually it specifies a business entity, loke:user
, or:order
. Default:nil
.
Examples
defmodule MyList do
defdelegatelog reverse(list), to: Enum
end
MyList.reverse([1, 2, 3])
# Logger.log is called under the hood with telemetry metrics attached
#=> [3, 2, 1]
# Logger.log is called under the hood with telemetry metrics attached