我一直在研究这个话题已经太久了,所以我必须发布这个.我有几个应用程序运行此设置,其中一个完全borks在rails启动(rails s).它们的配置几乎完全相同,但我似乎无法在大海捞针中找到它.有没有人对如何找到这个问题有任何指示?
设置基于:http://blog.mmlac.com/log4r-for-rails/comment-page-1/#comment-1731
当我尝试运行rails s时:
=> Booting WEBrick => Rails 4.0.0 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting /Users/chrishough/Placewise/code/ApiDigest/.bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:78:in `start': undefined method `formatter' for #<Log4r::Logger:0x007f85be89abe8> (NoMethodError) from /Users/chrishough/Placewise/code/ApiDigest/.bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>' from /Users/chrishough/Placewise/code/ApiDigest/.bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap' from /Users/chrishough/Placewise/code/ApiDigest/.bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>'
我如何在application.rb文件中配置log4r:
#log4r requirements require 'log4r' require 'log4r/yamlconfigurator' require 'log4r/outputter/datefileoutputter' include Log4r module DigestApi class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # ----------------------------------------------------------------------------------- # assign log4r's logger as rails' logger. log4r_config= YAML.load_file(File.join(File.dirname(__FILE__),"log4r.yml")) log_cfg = YamlConfigurator log_cfg["ENV"] = Rails.env log_cfg.decode_yaml(log4r_config['log4r_config']) # # disable standard Rails logging config.logger = Log4r::Logger['rails'] ActiveRecord::Base.logger = Log4r::Logger['sqlserver'] # #nice for multiple-instance webservers like unicorn # #to monitor (re-)starts # #log whenever a worker (re-)started Log4r::Logger['rails'].info "LAUNCH PUMA WORKER" # -----------------------------------------------------------------------------------
我的log4r.yml文件:
log4r_config: # define all loggers: loggers: - name : rails level : DEBUG trace : 'true' outputters : - console - rails_file - name : sqlserver level : DEBUG trace : 'false' outputters : - sqlserver_file - name : sqlserver_long_query level : DEBUG trace : 'false' outputters : - sqlserver_long_query_file - name : missing_route level : DEBUG trace : 'false' outputters : - missing_route_file # define all outputters (incl. formatters) outputters: - type: StdoutOutputter name: console formatter: date_pattern: '%H:%M:%S' pattern : '%d %l: %m' type : PatternFormatter - type: FileOutputter name: rails_file filename: "log/#{ENV}.log" trunc: false formatter: date_pattern: '%Y %m %d %H:%M:%S.%L %z' pattern : '%d %l: %m' type : PatternFormatter - type: FileOutputter name: sqlserver_file filename: "log/sql.log" trunc: false formatter: date_pattern: '%Y %m %d %H:%M:%S.%L %z' pattern : '%d %l: %m' type : PatternFormatter - type: FileOutputter name: sqlserver_long_query_file filename: "log/sql_qry_long.log" trunc: false formatter: date_pattern: '%Y %m %d %H:%M:%S.%L %z' pattern : '%d %l: %m' type : PatternFormatter - type: FileOutputter name: missing_route_file filename: "log/missing_route.log" trunc: false formatter: date_pattern: '%Y %m %d %H:%M:%S.%L %z' pattern : '%d %l: %m' type : PatternFormatter