Summary
ForestAdminRails.config.logger_level (and the equivalent logger_level passed to ForestAdminAgent::Services::LoggerService.new) has no effect when using the default logger. All levels — including Info and Debug — are printed regardless of the configured level.
Environment
forest_admin_agent 1.27.0
forest_admin_rails 1.30.2
Reproduction
# config/initializers/forest_admin_rails.rb
ForestAdminRails.configure do |config|
config.logger_level = "Warn"
end
Then run any command that goes through the agent (e.g. bin/rails forest_admin:schema:generate):
[ForestAdmin] Starting schema generation...
I, [...] INFO -- : unknown type 'inet' for field named ...
I, [...] INFO -- : [ForestAdmin] Schema generated successfully at ...
INFO lines still appear, even though logger_level is "Warn".
Root cause
In forest_admin_agent/lib/forest_admin_agent/services/logger_service.rb:
def initialize(logger_level = 'Info', logger = nil)
@logger_level = logger_level
@logger = logger
@default_logger = MonoLogger.new($stdout)
end
def log(level, message)
if @logger
eval(@logger).call(get_level(level), message)
else
@default_logger.add(get_level(level), message)
end
@logger || @default_logger
end
@logger_level is stored but never applied to @default_logger.
MonoLogger < Logger, and Logger's default @level is DEBUG (0), so @default_logger.add(severity, message) accepts every level.
@logger_level is effectively only consulted when the user supplies a custom config.logger (which is eval'd and expected to do its own filtering).
Result: on the default-logger code path, logger_level is a dead option.
Suggested fix
Apply the configured level to the default logger in initialize:
def initialize(logger_level = 'Info', logger = nil)
@logger_level = logger_level
@logger = logger
@default_logger = MonoLogger.new($stdout)
@default_logger.level = LEVELS.fetch(@logger_level, Logger::INFO)
end
Logger#add already respects @level, so this is enough to make the option behave as documented/expected. It also keeps behavior backward-compatible for the custom-logger path (that branch doesn't touch @default_logger).
Happy to open a PR if that would help.
Workaround
Prepend LoggerService and set the level manually:
ForestAdminAgent::Services::LoggerService.prepend(Module.new do
def initialize(logger_level = "Warn", logger = nil)
super
normalized = @logger_level.to_s.capitalize
@default_logger.level =
ForestAdminAgent::Services::LoggerService::LEVELS.fetch(normalized, Logger::WARN)
end
end)
Summary
ForestAdminRails.config.logger_level(and the equivalentlogger_levelpassed toForestAdminAgent::Services::LoggerService.new) has no effect when using the default logger. All levels — includingInfoandDebug— are printed regardless of the configured level.Environment
forest_admin_agent1.27.0forest_admin_rails1.30.2Reproduction
Then run any command that goes through the agent (e.g.
bin/rails forest_admin:schema:generate):INFO lines still appear, even though
logger_levelis"Warn".Root cause
In
forest_admin_agent/lib/forest_admin_agent/services/logger_service.rb:@logger_levelis stored but never applied to@default_logger.MonoLogger < Logger, andLogger's default@levelisDEBUG(0), so@default_logger.add(severity, message)accepts every level.@logger_levelis effectively only consulted when the user supplies a customconfig.logger(which iseval'd and expected to do its own filtering).Result: on the default-logger code path,
logger_levelis a dead option.Suggested fix
Apply the configured level to the default logger in
initialize:Logger#addalready respects@level, so this is enough to make the option behave as documented/expected. It also keeps behavior backward-compatible for the custom-logger path (that branch doesn't touch@default_logger).Happy to open a PR if that would help.
Workaround
Prepend
LoggerServiceand set the level manually: