Skip to content

Commit

Permalink
Move logger to an initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
miharekar committed Nov 10, 2023
1 parent bc8b2c9 commit a58b4dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 0 additions & 2 deletions config/appsignal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ default: &defaults
# See https://docs.appsignal.com/ruby/configuration/options.html for
# all configuration options.

log_path: "tmp/log"

# Configuration per environment, leave out an environment or set active
# to false to not push metrics for that environment.
development:
Expand Down
6 changes: 2 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = true

config.log_tags = [:request_id]
console_logger = ActiveSupport::Logger.new($stdout)
# Log to STDOUT by default
config.logger = ActiveSupport::Logger.new($stdout)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
appsignal_logger = ActiveSupport::TaggedLogging.new(Appsignal::Logger.new("rails"))
config.logger = ActiveSupport::BroadcastLogger.new(console_logger, appsignal_logger)

# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

if Rails.env.production?
console_logger = ActiveSupport::Logger.new($stdout)
appsignal_logger = ActiveSupport::TaggedLogging.new(Appsignal::Logger.new("rails"))
Rails.logger = ActiveSupport::BroadcastLogger.new(console_logger, appsignal_logger)
end

0 comments on commit a58b4dd

Please sign in to comment.