Closed kavinphan closed 1 year ago
No, not really. To be honest, I haven't considered wanting to see different logs in development and production so there isn't an easy mechanism for switching. You would basically have to revert the setup that's in the railtie.rb
.
Do you want to switch because of the readability or are you missing data (e.g. view render time)? If it's just about the format then you can use the logcraft.layout_options.formatter
configuration option to output nicer looking messages specifically in the development environment.
It was mainly for readability, but I ended up doing what you suggested and formatted the logs to look about the same. Also needed to mute the SQL SCHEMA
events-- those don't seem to appear in Rails's default logging. Thanks!
@kphan32 could you please share your formatter? Thank you!
# Adjust Logcraft verbosity by environment.
module LogVerbosity
module ByEnvironment
private
def background_of(event)
super.slice(*context_filter)
end
def context_filter
@context_filter ||= case Rails.env
when "production", "staging"
%w[timestamp level dd]
when "development", "test"
%w[level]
end
end
end
end
Logcraft::LogLayout.prepend(LogVerbosity::ByEnvironment)
In a Rails project, is there a way to disable Logcraft conditionally? Would love to use Logcraft in prod environments, but for local development I'd prefer the default Rails logger.