log4rruby-on-rails-6

rails6 log4r tagged_logging.rb:22:in `call': wrong number of arguments


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

This is the complete error information

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

Solution

  • 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
    

    refer to: https://www.thegreatcodeadventure.com/building-a-custom-logger-in-rails/