Skip to content
save all of your logs to an ecto repo.
Elixir
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
lib
priv/repo/migrations
test
.formatter.exs
.gitignore
.tool-versions
LICENSE
README.md
mix.exs
mix.lock

README.md

LoggerBackendEcto

What is it?

LoggerBackendEcto will allow you to save all of your logs to an ecto repo.

Why is it

This is very helpful for Nerves devices which don't always have network access, or console access.

Usage

Add logger backend ecto to your deps:

def deps do
  [
    {:logger_backend_sqlite, "~> 1.0"},
    {:sqlite_ecto2, "~> 2.2.4"} # or any other Ecto adapter.
  ]
end

Configure :ecto and :logger:

use Mix.Config

config :logger, [
  utc_log: true,
  handle_otp_reports: true,
  handle_sasl_reports: true,
  backends: [:console, LoggerBackendEcto]
]

config :logger_backend_ecto, [
  max_logs: 9000 # defaults to 1000
  trim_amnt: 3000 # defaults to 25% of `max_logs`
]

# This can be any adapter and config.
config :logger_backend_ecto, LoggerBackendEcto.Repo, [
  adapter: Sqlite.Ecto2,
  database: "elixir_logs.sqlite3"
]

You can also add the backend at runtime, however make sure the ecto repo is configured properly.

iex()> {:ok, _} = Logger.add_backend(LoggerBackendEcto)
require Logger
Logger.debug "hello, world!"
[%LoggerBackendEcto.Log{level: "debug", message: "hello, world!"}] = LoggerBackendEcto.all()
You can’t perform that action at this time.