larskrantz / logger_papertrail_backend

A Papertrail backend for Elixir Logger
MIT License
53 stars 13 forks source link

LoggerPapertrailBackend

Hex.pm Hex.pm Build Status

A Papertrail backend for Elixir Logger.

Changelog

Installation

Available in Hex. The package can be installed as:

def deps do
  [{:logger_papertrail_backend, "~> 1.1"}]
end
def application do
  [applications: [:logger, :logger_papertrail_backend]]
end
def application do
  [extra_applications: [:logger]]
end
config :logger, :logger_papertrail_backend,
  host: "logs.papertrailapp.com:<port>",
  level: :warn,
  system_name: "Wizard",
  metadata_filter: [],
  format: "$metadata $message"

Alternatively use :url for shorter config. Prepend with "papertrail://" (or whatever as long its a valid URI), then host:port/system_name. We normally set an ENV-var: url: System.get_env("PAPERTRAIL_URL") or url: "${PAPERTRAIL_URL}", if building releases with Distillery and REPLACE_OS_VARS=true.

config :logger, :logger_papertrail_backend,
  url: "papertrail://logs.papertrailapp.com:<port>/<system_name>",
  level: :warn,
  format: "$metadata $message"

Then config :logger to use the LoggerPapertrailBackend.Logger:

config :logger,
  backends: [ :console,
    LoggerPapertrailBackend.Logger
  ],
  level: :debug

Note: if you have an umbrella project, use your top config.exs.

Example output

Oct 02 14:19:04 Wizard UpptecSlack.SlackBot: [info] Successfully authenticated as user "wizard" on team "Upptec"

Papertrail sets timestamp when message arrives. Wizard is :system_name. UpptecSlack.SlackBot is the module sending the log. [Info] is level.