【问题标题】:rails6 log4r tagged_logging.rb:22:in `call': wrong number of argumentsrails6 log4r tagged_logging.rb:22:in `call': 参数数量错误
【发布时间】:2020-08-31 07:49:44
【问题描述】:

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

这是完整的错误信息

.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)

【问题讨论】:

    标签: log4r ruby-on-rails-6


    【解决方案1】:

    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/

    【讨论】:

      猜你喜欢
      • 2020-07-04
      • 2012-06-16
      • 2014-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多