Lumberjack DataDog Device

Build Status Maintainability

This gem provides a logging device that produces JSON output that matches the standard fields defined for DataDog logging.

  • The time will be sent as "timestamp" with a precision in microseconds.

  • The severity will be sent as "status" with a string label (DEBUG, INFO, WARN, ERROR, FATAL).

  • The progname will be sent as "logger.name"

  • The pid will be sent as "pid".

  • The message will be sent as "message". In addition, if the message is an exception, the error message, class, and backtrace will be sent as "error.message", "error.kind", and "error.trace".

  • If the "error" tag contains an exception, it will be sent as "error.message", "error.kind", and "error.trace".

  • A duration can be sent as a number of seconds in the "duration" tag or as a number of milliseconds in the "duration_ms" tag or as a number of microsectons in the "duration_micros" tag or as a number of nanoseconds in the "duration_ns" tag.

  • All other tags are sent as is. If a tag name includes a dot, it will be sent as a nested JSON structure.

This device extends from Lumberjack::JsonDevice. It is not tied to Data Dog in any way other than that it is opinionated about how to map and format some log tags. It can be used with other services or pipelines without issue.

You can optionally specify a maximum message length with the max_message_length option on the device. Doing so will trucate the message payload to keep it under this number of characters. This option is provided because JSON payloads get messed up and cannot be parsed if they get too big.

Example

You could log an HTTP request to some of the DataDog standard fields like this:

logger.tag("http.method" => request.method, "http.url" => request.url) do
  logger.info("#{request.method} #{request.path} finished in #{elapsed_time} seconds",
    duration: elapsed_time,
    "http.status_code" => response.status
  )
end