Semantic Logger formatter for submitting JSON logs to Datadog.
Add semantic_logger_datadog to your project's Gemfile and run bundle install:
gem "semantic_logger_datadog"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.
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.
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?
endImportant
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.
semantic_logger_datadog is freely available under the MIT License.