logger_json v0.4.0 LoggerJSON

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

By-default, generated JSON is compatible with Google Cloud Logger format with additional properties in serviceLocation and metadata objects:

  {
     "time":"2017-04-09T17:52:12.497Z",
     "severity":"DEBUG",
     "sourceLocation":{
        "moduleName":"Elixir.LoggerJSONTest",
        "line":62,
        "functionName":"test metadata can be configured to :all/1",
        "file":"/Users/andrew/Projects/logger_json/test/unit/logger_json_test.exs"
     },
     "metadata":{
        "user_id":11,
        "dynamic_metadata":5
     },
     "logMessage":"hello"
  }

You can change this structure by implementing LoggerJSON.Formatter behaviour and passing module name to :formatter config option. Example module can be found in LoggerJSON.Formatters.GoogleCloudLogger.

  config :logger_json, :backend,
    formatter: MyFormatterImplementation

Encoders support

You can replace default Poison encoder with other module that supports encode!/1 function. This can be even used as custom formatter callback.

Popular Poison alternatives:

If your application is performance-critical, take look at 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.

  config :logger_json, :backend,
    on_init: {YourApp.Logger, :load_from_system_env, []}

Summary

Functions

Callback implementation for c::gen_event.code_change/3

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

Callback implementation for c::gen_event.terminate/2

Functions

code_change(old_vsn, state, extra)

Callback implementation for c::gen_event.code_change/3.

handle_call(arg, state)

Callback implementation for c::gen_event.handle_call/2.

handle_event(arg1, state)

Callback implementation for c::gen_event.handle_event/2.

handle_info(arg1, state)

Callback implementation for c::gen_event.handle_info/2.

init(arg1)

Callback implementation for c::gen_event.init/1.

take_metadata(metadata, keys)
terminate(reason, state)

Callback implementation for c::gen_event.terminate/2.