https://github.com/seniverse/ex_json_logger_examples
Usage examples centered on JSON Logger in Elixir.
https://github.com/seniverse/ex_json_logger_examples
elixir elixir-logger examples json json-logger logger
Last synced: about 1 month ago
JSON representation
Usage examples centered on JSON Logger in Elixir.
- Host: GitHub
- URL: https://github.com/seniverse/ex_json_logger_examples
- Owner: seniverse
- License: mit
- Created: 2019-05-28T07:37:52.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-29T13:02:16.000Z (about 7 years ago)
- Last Synced: 2025-11-13T17:04:12.824Z (7 months ago)
- Topics: elixir, elixir-logger, examples, json, json-logger, logger
- Language: Elixir
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSONLoggerExamples
[](https://travis-ci.org/seniverse/ex_json_logger_examples)
Usage examples centered on how to log messages with JSON format in Elixir based on [ex_json_logger](https://github.com/rentpath/ex_json_logger).
See [test/json_logger_examples_test.exs](test/json_logger_examples_test.exs) for usage cases and [config/config.exs](config/config.exs) for how to do configuration for logger to set a custom formatter.
See [ex_json_logger - GitHub](https://github.com/rentpath/ex_json_logger) for more instructions about usage.
See [Logger - Elixir](https://hexdocs.pm/logger/Logger.html) for official doc about `Logger`.
## Try it out
```sh
$ 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](https://hexdocs.pm/logger/Logger.html#module-metadata) or other ways.
2. Just printing log to `stdout`. See [Logs - 12factor](https://12factor.net/logs) for its reason. Let's develop [Cloud-Native](https://pivotal.io/cloud-native) Apps!