Why are two loggers used in rails 3.2: ActiveSupport :: TaggedLogging and ActiveSupport :: BufferedLogger?

It looks like we have access to Rails.logger and logger inside Rails applications. I understand that the two registrars are different from each other, but it would not be ideal to create on TaggedBufferedLogger and have one instance for the log. Why are there two instances and what is the right time to use them?

+5
source share
1 answer

BufferedLogger is the default Rails registrar. Its goal is to log without threading. If you wish, you can wrap this logger in a TaggedBufferedLogger and use it if you want to "mark" your log output.

Straight from 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
+7
source

All Articles