rails_semantic_logger
rails_semantic_logger copied to clipboard
Respect the log level configured in Mongoid logger when overriding it with Semantic Logger
trafficstars
Environment
Provide at least:
-
Ruby Version: 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [x86_64-linux]
-
Rails Version: 7.0.8
-
Semantic Logger Version: 4.14.0
-
Rails Semantic Logger Version: 4.12.0
-
Rails configuration:
config.mongoid.logger.level = Logger::INFO
config.semantic_logger.add_appender(io: $stdout, formatter: :color)
Expected Behavior
- The debug level logs from
Mongoid.loggershould not be printed in the rails console. - Running
Mongoid.logger.levelshould return:info
Actual Behavior
- The debug level logs from
Mongoid.loggerare printed in the rails console - Running
Mongoid.logger.levelis returning:debug
Workaround
I have fixed this using the following configuration
config.after_initialize do
Mongoid.logger.level = Logger::INFO
end
PR
The override is happening here. Should be possible to read the configured log level from Mongoid.logger and reaint the value in SemanticLogger[Mongoid].
Open to reaising a PR after verifying this. Let me know your thoughts.