LoggerPSQL is a Logger backend that emits the logs to a PostgreSQL Repo.
** Added some customizations that's pretty unique to us. It would be nice if we could generalize and publish... **
Add logger_psql to your list of dependencies in mix.exs:
def deps do
[
{:logger_psql, "~> 0.1.3"}
]
endAdd the backend to the logger configuration:
config :logger,
backends: [LoggerPSQL],
level: :infoThen configure the logger_psql itself to the desired repo:
config :logger_psql, :backend,
level: :info,
repo: MyApp.LogRepo,
schema_name: "logs",
prefix: "",
metadata_filter: [:ansi_color, :color]Some of the fields for configuration are:
level:informs the lower level to be sent to the backendrepo:module defined by ecto to be the desired storage, it is recommended to have a separated repo from the main repo of the application for thisschema_name:table name to be created with the migration, if not set the value islogsprefix:database prefix, if not set the value is empty and goes directly into the ecto's default value ofpublicmetadata_filter:simple filter for metadata to not be stored in the database
Generate and run the migrations from the CLI:
mix logger_psql.gen.migrationmix ecto.migrate
NOTE After running the migrations please take note of changing the configs for
schema_nameandprefix, if needed to change after running the migrations, please create the migrations accordingly.
Many source code has been taken from original Elixir Logger :console and logger_json back-end source code, so I want to thank all it's authors and contributors.
Part of Mix.Tasks.LoggerPsql.Gen.Migration module was based in the guardian_db gen.migration task guardian_db.