本文介绍了rails6 log4r tagged_logging.rb:22:in `call':参数数量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在rails 6中使用log4r时,报如下错误

When I use log4r in rails 6, I report the following error

这是完整的错误信息

.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/tagged_logging.rb:22:in `call': wrong number of arguments (given 0, expected 4) (ArgumentError)

推荐答案

config/initializers/log4r_patch.rb

class Log4r::Logger
  def formatter()
    Proc.new{|severity, time, progname, msg|
      formatted_severity = sprintf("%-5s",severity.to_s)
      formatted_time = time.strftime("%Y-%m-%d %H:%M:%S")
      "[#{formatted_severity} #{formatted_time} #{$$}]\n #{msg}\n"
    }
  end
  def formatter=(temp)
  end
end

参考:https://www.thegreatcodeadventure.com/building-a-custom-logger-in-rails/

这篇关于rails6 log4r tagged_logging.rb:22:in `call':参数数量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 13:02