Hey Mark,
I’m still on Rails 1.0 for the project that uses Log4R and although I
know there are 1 or 2 bugs in trac for rails integrating with it, most
things should be the same…
Also, I am deployed on FreeBSD under lighty so there should be no
problems with your setup.
In environment/rb I’ve got a require “logger” which is another file in
the environment dir
In logger.rb, I’ve copied a lot of the sample code off the log4r site,
but it looks pretty much like this:
[snip]
Configure logging.
We use various outputters, so require them, otherwise config chokes
require ‘log4r’
require ‘log4r’
require ‘log4r/yamlconfigurator’
require ‘log4r/outputter/fileoutputter’
require ‘log4r/outputter/datefileoutputter’
require ‘log4r/outputter/emailoutputter’
cfg = Log4r::YamlConfigurator
cfg[‘RAILS_ROOT’] = RAILS_ROOT
cfg[‘RAILS_ENV’] = RAILS_ENV
load the YAML file with this
cfg.load_yaml_file(“#{RAILS_ROOT}/config/log4r.yaml”)
RAILS_DEFAULT_LOGGER = Log4r::Logger[‘default’]
RAILS_DEFAULT_LOGGER.level = (RAILS_ENV == ‘development’ ?
Log4r::DEBUG : Log4r::INFO)
if RAILS_ENV == ‘test’
Log4r::Outputter[‘stderr’].level = Log4r::OFF
RAILS_DEFAULT_LOGGER.add( Log4r::Outputter[‘stderr_test’] )
end
if RAILS_ENV == ‘production’
Log4r::Outputter[‘standardlog’].level = Log4r::OFF
Log4r::Outputter[‘stderr’].level = Log4r::OFF
else
Log4r::Outputter[‘email’].level = Log4r::OFF
end
[/snip]
As you can see, I decided to keep the logger configuration all in one
place (out of the /environments/*.rb files). Note that this does not
include my log4r.yaml file, but it is heavily based on the
log4r_yaml.yaml file in the examples directory from the gem. My
stderr_test outputter is just like my stderr one but more verbose log
detail (using the ‘slow’ formatters) and it only outputs at ERROR not
WARN which keeps those Rake runs mostly free from error messages.
Note the line “RAILS_DEFAULT_LOGGER = Log4r::Logger[‘default’]” - this
is the line that tells Rails not to set up its own logger, with
“default” defined like this:
[snip]
loggers:
- name : default
level : DEBUG
additive : ‘false’
trace : ‘true’
outputters:
- stderr
- datefilelog
- standardlog
- email
[/snip]
I should point out that in the last if/else block that I am turning
off logging to the “production.log” file and only logging to a
DateFileOutputter (so that mu production logs look like
“dispatcher.fcgi.20060412.log”
[snip]
- type : DateFileOutputter
name : datefilelog
level : DEBUG
date_pattern: ‘%Y%m%d’
trunc : ‘false’
dirname : “#{RAILS_ROOT}/log”
formatter :
date_pattern: ‘%y%m%d %H:%M:%S’
#pattern : '%d %l: %m ’
pattern : “[%l] %d :: %m”
type : PatternFormatter
[/snip]
Hope that helps!
Dan
–
Dan S.
www.peoplehub.com.au
www.dansketcher.com