Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does rails 3.2 use two loggers, ActiveSupport::TaggedLogging and ActiveSupport::BufferedLogger?

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?

like image 905
Kamilski81 Avatar asked May 30 '12 12:05

Kamilski81


1 Answers

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
like image 200
Salil Avatar answered Sep 23 '22 00:09

Salil