Last active
March 8, 2018 11:57
-
-
Save Lupeipei/7297b1a784e7bb4da39eeb7d26c8d834 to your computer and use it in GitHub Desktop.
配置log4r
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 修改config/application.rb | |
require 'rails/all' | |
# add these line for log4r | |
require 'log4r' | |
require 'log4r/yamlconfigurator' | |
require 'log4r/outputter/datefileoutputter' | |
Bundler.require(:default, Rails.env) if defined?(Bundler) | |
module Zurich | |
class Application < Rails::Application | |
#... | |
# assign log4r's logger as rails' logger. | |
include 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 新建一个log4r的配置文件: config/log4r.yml | |
log4r_config: | |
# define all loggers ... | |
loggers: | |
- name : production | |
level : WARN | |
trace : 'false' | |
outputters : | |
- datefile | |
- name : development | |
level : DEBUG | |
trace : 'true' | |
outputters : | |
- datefile | |
# define all outputters (incl. formatters) | |
outputters: | |
- type: DateFileOutputter | |
name: datefile | |
dirname: "log" | |
filename: "my_app.log" # notice the file extension is needed! | |
formatter: | |
date_pattern: '%H:%M:%S' | |
pattern : '%d %l: %m ' | |
type : PatternFormatter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 新建文件:config/initializers/log4r_patch_for_rails4.rb | |
class Log4r::Logger | |
def formatter() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment