Kam*_*i81 5 logging ruby-on-rails-3
看来我们可以访问Rails应用程序中的Rails.logger和logger.我知道这两个记录器是不同的,但是在TaggedBufferedLogger上创建并且只有一个logger实例是不理想的.为什么有两个实例,什么是适当的使用时间?
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
Run Code Online (Sandbox Code Playgroud)