A logger backend for elixir to send application logs to LogDNA through their ingestion API.
The package can be installed by adding ex_logdna
to your list of dependencies in mix.exs
:
def deps do
[
{:ex_logdna, "~> 0.1.0"}
]
end
First configure your logger to use the LogDNA backend. It also respects the level
and metadata
configuration.
config :logger, backends: [LogDNA], level: :info, metadata: [:request_id, :event, :tags]
Then configure the backend with some LogDNA specific configurations.
config :ex_logdna,
ingestion_key: System.get_env("LOGDNA_INGESTION_KEY"),
app: "my-app",
hostname: "localhost",
tags: ["web", "prod"]
Find more information in the LogDNA ingestion API documentation.
After configuring your application to use the LogDNA
backend, just use logger as you normally would. To send a log entry with log level info
for instance:
Logger.info("Logging stuff to LogDNA")
The backend has support for metadata, just pass it on as the second argument:
Logger.info("Logging stuff to LogDNA with additional metadata.", user_id: "some-user-id")
Some metadata properties are reserved for magic.
If you pass in tags
with your log entry, it won't be sent in as metadata, but as native LogDNA tags.
Logger.info("Logging stuff to LogDNA with additional metadata.", tags: ["one", "two"])
Should you have configured global tags in your config file, these event tags will be merged into the global tags, and they are all passed along to the ingestion API.