It appears that we have access to Rails.logger and logger inside Rails applications. I understand that the two logger are different, but wouldnt it be ideal to create on TaggedBufferedLogger and have a single instance for logger. Why are there two instances and what is the proper time to use which?
BufferedLogger is the default Rails logger. Its purpose is to make logging thread-safe. Optionally, you can wrap this logger into a TaggedBufferedLogger and use it, if you want to 'tag' your logging output.
Straight from the weblog.rails
Tagged logger
When you’re running a multi-user, multi-account application, it’s a great help to be able to filter the log by who did what. Enter the TaggedLogging wrapper. It works like this:
Logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
Logger.tagged("BCX") { Logger.info "Stuff" } # Logs "[BCX] Stuff"
Logger.tagged("BCX") do
Logger.tagged("Jason") do
Logger.info "Stuff" # Logs "\[BCX\] \[Jason\] Stuff"
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With