【问题标题】:Why does rails 3.2 use two loggers, ActiveSupport::TaggedLogging and ActiveSupport::BufferedLogger?为什么 rails 3.2 使用两个记录器,ActiveSupport::TaggedLogging 和 ActiveSupport::BufferedLogger?
【发布时间】:2012-05-30 12:56:39
【问题描述】:

看起来我们可以访问 Rails.logger 和 Rails 应用程序中的记录器。我知道这两个记录器是不同的,但是在 TaggedBufferedLogger 上创建并拥有一个记录器实例不是理想的选择。为什么会有两个实例,什么时候使用哪个合适?

【问题讨论】:

    标签: ruby-on-rails-3 logging


    【解决方案1】:

    BufferedLogger 是默认的 Rails 记录器。它的目的是使日志记录线程安全。 或者,如果您想“标记”您的日志记录输出,您可以将此记录器包装到 TaggedBufferedLogger 中并使用它。

    直接来自 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
    

    【讨论】:

      猜你喜欢
      • 2020-03-19
      • 2023-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多