Skip to content

Instantly share code, notes, and snippets.

@STAR-ZERO
Created February 26, 2013 06:25
Show Gist options
  • Select an option

  • Save STAR-ZERO/5036348 to your computer and use it in GitHub Desktop.

Select an option

Save STAR-ZERO/5036348 to your computer and use it in GitHub Desktop.
log4rの使い方
# config/application.rb
require 'rails/all'
require 'log4r'
require 'log4r/yamlconfigurator'
require 'log4r/outputter/datefileoutputter'
include Log4r
module HogeHoge
class Application < Rails::Application
# ...
#
# log4r
log4r_config= YAML.load_file(File.join(File.dirname(__FILE__), 'log4r.yml'))
YamlConfigurator.decode_yaml(log4r_config['log4r_config'])
config.logger = Log4r::Logger[Rails.env]
end
end
# Gemfile
gem 'log4r'
# config/log4r.yml
log4r_config:
loggers:
- name : development
level : DEBUG
trace : 'true'
outputters :
- development_log
- name : test
level : DEBUG
trace : 'true'
outputters :
- test_log
- name : production
level : WARN
trace : 'false'
outputters :
- production_log
outputters:
- type: FileOutputter
name: development_log
filename: 'log/development.log'
formatter:
date_pattern: '%Y/%m/%d %H:%M:%S'
pattern : '%d [%l]: %M'
type : PatternFormatter
- type: FileOutputter
name: test_log
filename: 'log/test.log'
formatter:
date_pattern: '%Y/%m/%d %H:%M:%S'
pattern : '%d [%l]: %M'
type : PatternFormatter
- type: FileOutputter
name: production_log
filename: 'log/production.log'
formatter:
date_pattern: '%Y/%m/%d %H:%M:%S'
pattern : '%d [%l]: %M'
type : PatternFormatter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment