Closed ngollan closed 2 years ago
Workaround after starting the console, sets any appender spamming STDERR to a higher log level:
SemanticLogger.appenders.select {|a| a.instance_variable_get('@log') == STDERR }.each {|a| a.level = :error }; nil
A more nuclear option is to put the below in an initialiser to prevent any appender to STDERR
:
module STFUConsoleLogging
module ClassMethods
def add_appender(*args, **kwargs)
unless kwargs[:io] == STDERR
super
end
end
end
def self.prepended(base)
class << base
prepend ClassMethods
end
end
end
SemanticLogger.prepend(STFUConsoleLogging)
Agreed, make it configurable.
The issue is that the default Rails behaviour can be changed with relatively easy means (setting the AR logger). SemanticLogger replicates that functionality in a way that requires manipulating non-obvious interfaces and that cannot be circumvented without intrusive code. By default, logging to STDERR is done at "trace" level, i.e., maximally verbose too, and I do not see a way to change that except for changing the entire project's default log level (if that is even possible before the console
block runs). The functionality could, however, be replicated by any consumer who needs it by putting the code block into a project.
In that light, I would see it warranted to revert the "fix" for #83 until there is a friendlier way.
Console logging in Rails console is now configurable: https://github.com/reidmorrison/rails_semantic_logger/commit/6684880d013af1ddc47b7e16dffe61d4f60217d9
Configuration option to set to disable the built in rails console logger:
config.rails_semantic_logger.console_logger = false
Just need to test it and publish a new gem version. Otherwise try pointing to master for now.
Please consider reverting afee72343e099142ffda7a9431d194c6e1744e3b or introduce an option to enable log replication to an irb console. As it stands, the only way to get rid of ActiveRecord console spam is to disable ActiveRecord logging by
silence
ing the logger. It should be easy enough to introduce logging in an application if desired by replicating theconsole
call, but as it stands, using the console in a nontrivial application has become extremely annoying.