Log ecto data as JSON with slightly different fields
- Poison
- Ecto
If available in Hex, the package can be installed as:
- Add
ecto_logger_json
to your list of dependencies inmix.exs
:
```elixir
def deps do
[{:ecto_logger_json, "~> 0.1.0"}]
end
```
- Ensure
ecto_logger_json
is started before your application:
```elixir
def application do
[applications: [:ecto_logger_json]]
end
```
- Configure ecto logging in
config/enviroment_name.exs
```elixir
config :my_app, MyApp.Repo,
adapter: Ecto.Adapters.Postgres,
...
loggers: [{Ecto.LoggerJSON, :log, [:info]}]
```
My recommendation would be to only log to a file and not console otherwise stdout when you are in iex gets very noisy from all the db logs.
-
Configure the logger (console)
-
Add to your
config/config.exs
orconfig/env_name.exs
:config :logger, :console, format: "$message\n", level: :info, metadata: [:request_id]
-
-
Configure the logger (file)
-
Add
{:logger_file_backend, "~> 0.0.7"}
to your mix.exs -
Run
mix deps.get
-
Add to your
config/config.exs
orconfig/env_name.exs
:config :logger, format: "$message\n", backends: [{LoggerFileBackend, :log_file}, :console] config :logger, :log_file, format: "$message\n", level: :info, metadata: [:request_id], path: "log/my_pipeline.log"
-
Before submitting your pull request, please run:
mix credo --strict
mix coveralls
mix dialyzer
Please squash your pull request's commits into a single commit with a message and detailed description explaining the commit.