No release in over 3 years
Semantic Logger formatter for submitting JSON logs to Datadog.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

semantic_logger_datadog

Semantic Logger formatter for submitting JSON logs to Datadog.

Gem Downloads Build

Installation

Add semantic_logger_datadog to your project's Gemfile and run bundle install:

gem "semantic_logger_datadog"

Usage

require "semantic_logger_datadog"

# Set the global default log level.
SemanticLogger.default_level = :trace

# Log to a file, and use the Datadog formatter.
SemanticLogger.add_appender(file_name: "development.log", formatter: SemanticLoggerDatadog::Formatters::Json.new)

# Create an instance of a logger and add the class name to every log message.
logger = SemanticLogger["MyClass"]

# Log an info message to devleopment.log
logger.info "Hello, world!"

Refer to Semantic Logger's documentation for more customization options.

Configuring Ruby on Rails

In addition to semantic_logger_datadog, add the rails_semantic_logger gem to your project's Gemfile:

gem "rails_semantic_logger"
gem "semantic_logger_datadog"

The included middleware configures relevant log tags using values provided by Action Dispatch.

Adding custom controller action data

Optionally configure user-specific data in app/controllers/application_controller.rb by adding an append_info_to_payload method:

def append_info_to_payload(payload)
  super

  payload[:usr] = current_user.slice(:id, :name, :email) if user_signed_in?
end

Important

Be extremely careful when logging personally-identifiable information. If you aren't required to log this information for legal or regulatory reasons, don't! Your logs can't leak data they never stored in the first place.

License

semantic_logger_datadog is freely available under the MIT License.