seniverse / ex_json_logger_examples

Usage examples centered on JSON Logger in Elixir.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSONLoggerExamples

Build Status

Usage examples centered on how to log messages with JSON format in Elixir based on ex_json_logger.

See test/json_logger_examples_test.exs for usage cases and config/config.exs for how to do configuration for logger to set a custom formatter.

See ex_json_logger - GitHub for more instructions about usage.

See Logger - Elixir for official doc about Logger.

Try it out

$ iex -S mix
iex> JSONLoggerExamples.log "abc"
:ok
iex> {"time":"2019-05-29 17:31:31.424","pid":"#PID<0.197.0>","msg":"abc","module":"Elixir.JSONLoggerExamples","line":6,"level":"info","function":"log/1","file":"lib/json_logger_examples.ex","application":"ex_json_logger_examples"}

It shows how actual messages printed in an Elixir module looks like in practice.

Explanations

  1. JSON is friendly for fields extension. We can add any fields we want in practice to a JSON via Logger.Metadata or other ways.

  2. Just printing log to stdout. See Logs - 12factor for its reason. Let's develop Cloud-Native Apps!

About

Usage examples centered on JSON Logger in Elixir.

License:MIT License


Languages

Language:Elixir 100.0%