Skip to content

Commit 6684880

Browse files
committed
Make it configurable whether to add the stderr logger when running a rails console
1 parent 76b32d7 commit 6684880

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/rails_semantic_logger/engine.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class Engine < ::Rails::Engine
123123

124124
# Replace the Bugsnag logger
125125
Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
126+
127+
# Set the IOStreams PGP logger
128+
IOStreams::Pgp.logger = SemanticLogger["IOStreams::Pgp"] if defined?(IOStreams)
126129
end
127130

128131
# After any initializers run, but after the gems have been loaded
@@ -218,7 +221,9 @@ class Engine < ::Rails::Engine
218221
console do |_app|
219222
# Don't use a background thread for logging
220223
SemanticLogger.sync!
221-
SemanticLogger.add_appender(io: STDERR, formatter: :color)
224+
if config.rails_semantic_logger.console_logger
225+
SemanticLogger.add_appender(io: STDERR, formatter: :color)
226+
end
222227

223228
# Include method names on log entries in the console
224229
SemanticLogger.backtrace_level = SemanticLogger.default_level

lib/rails_semantic_logger/options.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ module RailsSemanticLogger
4848
#
4949
# config.rails_semantic_logger.quiet_assets = false
5050
#
51+
# * Disable automatic logging to stderr when running a Rails console.
52+
#
53+
# config.rails_semantic_logger.console_logger = false
54+
#
5155
# * Override the output format for the primary Rails log file.
5256
#
5357
# Valid options:
@@ -98,7 +102,7 @@ module RailsSemanticLogger
98102
# config.rails_semantic_logger.named_tags = nil
99103
class Options
100104
attr_accessor :semantic, :started, :processing, :rendered, :ap_options, :add_file_appender,
101-
:quiet_assets, :format, :named_tags, :filter
105+
:quiet_assets, :format, :named_tags, :filter, :console_logger
102106

103107
# Setup default values
104108
def initialize
@@ -112,6 +116,7 @@ def initialize
112116
@format = :default
113117
@named_tags = nil
114118
@filter = nil
119+
@console_logger = true
115120
end
116121
end
117122
end

0 commit comments

Comments
 (0)