Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONLogFormatter

A JSON one-line log formatter for Elixir's Logger.

Installation

Add :json_log_formatter to the project's dependencies in the mix.exs file:

def deps do
  [
    {:json_log_formatter, "~> 1.0.0"}
  ]
end

And then fetch your project's dependencies: mix deps.get

Usage

Configure the console backend (or any other Logger backend in use) to use this module for formatting:

config :logger, :default_formatter, format: {JSONLogFormatter, :format}

The formatter expects timestamps in UTC, so Logger should be configured accordingly:

config :logger, :default_formatter, utc_log: true

It's also recommended to disable colors:

config :logger, :default_formatter, colors: [enabled: false]

Metadata values that cannot be encoded to JSON are rendered via inspect/2. The options passed to inspect/2 can be configured with:

config :json_log_formatter, inspect: [limit: 50, printable_limit: 4096]

Multi-line messages are emitted as a single JSON entry by default, with newlines escaped in the message field. To split each line into a separate log entry instead, configure:

config :json_log_formatter, split_multiline_messages: true

See the JSONLogFormatter module documentation for more details.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/supranode/json_log_formatter.

Copyright and License

JSONLogFormatter source code is licensed under the MIT License.

About

A JSON one-line log formatter

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages