我使用以下教程配置我的rails应用程序http://blog.mmlac.com/log4r-for-rails/
中的日志记录log4r.yml
log4r_config:
pre_config:
custom_levels:
- DEBUG
- PARAMS
- INFO
- WARN
- ERROR
- EXCEPTION
- FATAL
# define all loggers ...
loggers:
- name : rails
level : DEBUG
trace : 'false'
outputters :
- console
- railsfiledebug
- name : mysql
level : DEBUG
trace : 'false'
outputters :
- console
- railsfile
# 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: railsfile
filename: "log/cryptoserver_#{ENV}.log" # notice the file extension is needed!
trunc: false
formatter:
date_pattern: '%Y %m %d %H:%M:%S.%L %z'
pattern : '[#{EC2_INSTANCE}][%p][#{APPNAME}]|[RAILS][%d][%l]: %m '
type : PatternFormatter
在我的application.rb中:
Rails.logger = Log4r::Logger['rails']
如何配置记录器以生成两个单独的文件:
1)debug.log,其中记录优先级为DEBUG且更少的所有消息。
2)app.log,其中显示与debug.log中相同的消息,但DEBUG和PARAMS除外
所以
Rails.logger.info 'this should go in two log files'
Rails.logger.debug 'this should go in debug.log only'
答案 0 :(得分:1)
我意识到我可以使用两个具有不同错误级别的FileOutputter
- type: FileOutputter
name: railsfile
level: INFO
filename: "log/cryptoserver_#{ENV}.log" # notice the file extension is needed!
trunc: false
formatter:
date_pattern: '%Y %m %d %H:%M:%S.%L %z'
pattern : '[#{EC2_INSTANCE}][%p][#{APPNAME}]|[RAILS][%d][%l]: %m '
type : PatternFormatter
- type: FileOutputter
name: railsfiledebug
level: DEBUG
filename: "log/debug_#{ENV}.log" # notice the file extension is needed!
trunc: false
formatter:
date_pattern: '%Y %m %d %H:%M:%S.%L %z'
pattern : '[#{EC2_INSTANCE}][%p][#{APPNAME}]|[RAILS][%d][%l]: %m '
type : PatternFormatter