LoggerJSON.Formatters.Datadog (logger_json v7.0.3)
View SourceCustom Erlang's :logger formatter which
writes logs in a structured format that can be consumed by Datadog.
This formatter adheres to the default standard attribute list as much as possible.
Formatter Configuration
The formatter can be configured with the following options:
:hostname(optional) - changes how thesyslog.hostnameis set in logs. By default, it uses:systemwhich uses:inet.gethostname/0to resolve the value. If you are running in an environment where the hostname is not correct, you can hard code it by settinghostnameto a string. In places where the hostname is inaccurate but also dynamic (like Kubernetes), you can sethostnameto:unsetto exclude it entirely. You'll then be relying ondd-agentto determine the hostname.:reported_levels(optional) - a list of log levels that should be reported as errors to Datadog. Default:[:emergency, :alert, :critical, :error].
For list of shared options see "Shared options" in LoggerJSON.
Metadata
For list of other well-known metadata keys see "Metadata" in LoggerJSON.
Examples
%{
"domain" => ["elixir"],
"logger" => %{
"file_name" => "/Users/andrew/Projects/os/logger_json/test/formatters/datadog_test.exs",
"line" => 44,
"method_name" => "Elixir.LoggerJSON.Formatters.DatadogTest.test logs an LogEntry of a given level/1",
"thread_name" => "#PID<0.234.0>"
},
"message" => "Hello",
"syslog" => %{
"hostname" => "MacBook-Pro",
"severity" => "notice",
"timestamp" => "2024-04-11T23:03:39.726Z"
}
}