Skip to content
This repository was archived by the owner on Jul 25, 2025. It is now read-only.

Commit 85f6d88

Browse files
committed
Refactor Logtail logger configuration in application.rb to conditionally set logger based on environment variables
1 parent d53f60e commit 85f6d88

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

config/application.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@ class Application < Rails::Application
2626
# config.time_zone = "Central Time (US & Canada)"
2727
# config.eager_load_paths << Rails.root.join("extras")
2828
config.active_support.to_time_preserves_timezone = :zone
29+
30+
if ENV["LOGTAIL_API_KEY"].present? && ENV["LOGTAIL_INGESTING_HOST"].present?
31+
config.logger = Logtail::Logger.create_default_logger(ENV["LOGTAIL_API_KEY"], ingesting_host: ENV["LOGTAIL_INGESTING_HOST"])
32+
end
2933
end
3034
end

config/environments/production.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@
4545
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
4646
config.force_ssl = true
4747

48-
# Log to Logtail if API key is present, otherwise log to STDOUT
49-
config.logger = if ENV["LOGTAIL_API_KEY"].present?
50-
Logtail::Logger.create_default_logger(
51-
ENV["LOGTAIL_API_KEY"],
52-
ingesting_host: ENV["LOGTAIL_INGESTING_HOST"]
53-
)
54-
else
55-
ActiveSupport::Logger.new(STDOUT)
56-
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
57-
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
58-
end
59-
6048
# Prepend all log lines with the following tags.
6149
config.log_tags = [ :request_id ]
6250

0 commit comments

Comments
 (0)