问题描述
我一直在研究这个主题太久了,所以我必须发布这个.我有几个应用程序在运行这个设置,其中一个在 rails 启动(rails s)时完全停止.它们的配置几乎完全相同,但我似乎无法在这里大海捞针.有没有人有任何关于如何找到这个问题的指示?
I have been researching this topic for far too long now, so I have to post this. I have a few applications running this setup and one of them completely borks on rails startup (rails s). They are both configured nearly the exact same, but I can not seem to find the needle in the haystack here. Does anyone have any pointers on how to find this issue?
设置基于:http://blog.mmlac.com/log4r-for-rails/comment-page-1/#comment-1731
当我尝试运行 rails s 时:
when I try to run 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:
how I have log4r configured in my application.rb file:
#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 文件:
My log4r.yml file:
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
推荐答案
查看这篇文章 [1] 您可能还需要导入 FileOutputter.不太确定.
Looking at this post [1] you might have to import the FileOutputter as well. Not really sure.
我认为当其他服务器工作正常时,这是一个导入问题.只需尝试从 Log4r 导入您可能使用的所有内容,并确保您不会直接在其他地方的记录器上调用 [1] 提到的函数.
I think it's an import issue when the other server works fine.Just try to import everything you might possibly use from Log4r and make sure you don't call in [1] mentioned functions directly on the logger somewhere else.
如果这不起作用,请尝试以编程方式设置一个简单的记录器,然后将该记录器移动到 .yml,然后将其扩展回原来的位置.
If that does not work, try setting up a simple logger programmatically, then move that logger to the .yml and then expand it back to where it was before.
希望对您有所帮助,如果您需要更多帮助,请告诉我
Hope this helps you, let me know if you need more help
[1] RAILS 4.0 中 Log4r 的未定义方法格式化程序
这篇关于rails 4 log4r server.rb:78:in `start': 未定义的方法 `formatter'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!