Logging Elixir application on Graylog on OVH or similar cloud providers

Apr 13, 2018 . 1 min read

A logger backend that will generate Graylog Extended Log Format messages.

Taking advatage of Elixir logger API, gelf_logger

  • Add gelf_logger to your list of dependencies in mix.exs:
def deps do
  [{:gelf_logger, "~> 0.7.3"}]
end
  • Ensure logger and gelf_logger is started before your application (pre Elixir 1.4):
def application do
  [extra_applications: [:logger]]
end

Configuration

  • In your config.exs (or in your #{Mix.env}.exs-files):
config :logger,
  backends: [:console, {Logger.Backends.Gelf, :gelf_logger}]

  config :logger, :gelf_logger,
      port: 2202,
      application: "aadya",
      compression: :raw,
      metadata: [:request_id, :function, :module, :file, :line],
      host: "<server_host>.logs.ovh.com",
      tags: [
         "X-OVH-TOKEN": "xxxxxxxx-x-x-x-xxx-xxx"
      ]

Output

Success

Error