LoggerJSON (logger_json v5.1.2) View Source
JSON console back-end for Elixir Logger.
It can be used as drop-in replacement for default :console Logger back-end in cases where you use
use Google Cloud Logger or other JSON-based log collectors.
Log Format
LoggerJSON provides three JSON formatters out of the box.
You can change this structure by implementing LoggerJSON.Formatter behaviour and passing module
name to :formatter config option. Example implementations can be found in LoggerJSON.Formatters.GoogleCloudLogger,
LoggerJSON.Formatters.DatadogLogger, and LoggerJSON.Formatters.BasicLogger.
config :logger_json, :backend,
formatter: MyFormatterImplementationIf your formatter supports different options, you can specify them with :formatter_opts.
config :logger_json, :backend,
formatter: LoggerJSON.Formatters.DatadogLogger,
formatter_opts: %{hostname: "example.com"}Encoders support
You can replace default Jason encoder with other module that supports encode!/1 function. This can be even used
as custom formatter callback.
Popular Jason alternatives:
- poison.
- exjsx.
- elixir-json - native Elixir encoder implementation.
- jiffy.
Dynamic configuration
For dynamically configuring the endpoint, such as loading data
from environment variables or configuration files, LoggerJSON provides
an :on_init option that allows developers to set a module, function
and list of arguments that is invoked when the endpoint starts. If you
would like to disable the :on_init callback function dynamically, you
can pass in :disabled and no callback function will be called.
config :logger_json, :backend,
on_init: {YourApp.Logger, :load_from_system_env, []}
Link to this section Summary
Functions
Callback implementation for :gen_event.code_change/3.
Changes Logger log level at runtime.
Configures Logger log level at runtime by using value from environment variable.
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.
Changes Logger log level at runtime.
Notice that settings this value below compile_time_purge_level would not work,
because Logger calls would be already stripped at compile-time.
Configures Logger log level at runtime by using value from environment variable.
By default, 'LOG_LEVEL' environment variable is used.
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.