带有rails 4.2.4

时间:2016-09-16 06:19:29

标签: ruby-on-rails-4 log4r

我尝试使用我的应用程序配置log4r: 宝石信息: 宝石' log4r',' 1.1.10' gem' rails',' 4.2.4' gem' mysql2',' 0.3.20'

application.rb中

require 'log4r'
require 'log4r/yamlconfigurator'
require 'log4r/outputter/datefileoutputter'
include Log4r

在Application类中:

log4r_config = YAML.load_file(File.join(File.dirname(__FILE__), "log4r.yml"))
log_cfg      = YamlConfigurator
log_cfg.decode_yaml( log4r_config['log4r_config'] )

config.logger             = Log4r::Logger['rails']
config.log_level          = DEBUG
ActiveRecord::Base.logger = Log4r::Logger['mysql']

配置/ log4r.yml

log4r_config:
  pre_config:
    custom_levels:
      - DEV0
      - DEBUG
      - PARAMS
      - DEV1
      - INFO
      - WARN
      - ERROR
      - EXCEPTION
      - FATAL

 #
 # define all loggers:
 #
 loggers:
   - name          : rails
     level         : DEBUG
     trace         : 'false'
     outputters    : 
       - console
       - rails_file

   - name          : mysql
     level         : DEBUG
     trace         : 'false'
     outputters    :
       - console
       - rails_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

当我开始申请时,我得到以下错误:

=> Booting WEBrick
=> Rails 4.2.4 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/application/bootstrap.rb:70:in ***`const_get': wrong constant name 2 (NameError)***
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/application/bootstrap.rb:70:in `block in <module:Bootstrap>'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `run'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `call'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
    from /home/softices/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/application.rb:352:in `initialize!'
    from /home/softices/personal/workspace/ruby/trusted-driver/rails/admin/config/environment.rb:5:in `<top (required)>'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'
    from /home/softices/personal/workspace/ruby/trusted-driver/rails/admin/config.ru:3:in `block in <main>'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'
    from /home/softices/personal/workspace/ruby/trusted-driver/rails/admin/config.ru:in `new'
    from /home/softices/personal/workspace/ruby/trusted-driver/rails/admin/config.ru:in `<main>'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands/server.rb:61:in `app'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands/server.rb:139:in `log_to_stdout'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands/server.rb:78:in `start'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /home/softices/.rvm/gems/ruby-2.3.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

1 个答案:

答案 0 :(得分:0)

我得到了解决方案。我需要从application.rb中删除下面的配置行:

config.log_level = DEBUG