Skip to content

Files

Latest commit

c700944 · May 29, 2019

History

History
27 lines (17 loc) · 1.45 KB

README.md

File metadata and controls

27 lines (17 loc) · 1.45 KB

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!