John W. Long wrote:> Rick Olson wrote:
> >> This is an attempt to create a robust logger for Rails that
supports
> >> log rotation and other features.
> >
> > log4r might be what you''re looking for, and should be a
drop-in
> > replacement for the basic rails logger.
>
> Hey, thanks Rick. I''ve used log4r before and haven''t
found it very
> usable. It seems very clunky and not very Rubyish. I wanted something
> simple and log4r seemed to be the swiss army knife of logging. It had
> everything and the tools it had tended to make it hard to get to the
> important ones... The logging code I''ve added in my patch is quite
a bit
> simpler. Much more along the lines of logger.rb.
To see the simplicity of ActionLogger in action, consider what you would
have to do to get the following from log4r (taken from the patched
environment.rb):
RAILS_PROGRAM_NAME = ''My Rails Application''
LOG_FILENAME = "#{RAILS_ROOT}/log/#{RAILS_ENV}-%Y%m%d.log"
# Configure defaults if the included environment did not.
unless defined? RAILS_DEFAULT_LOGGER
RAILS_DEFAULT_LOGGER = ActiveLogger.new(
:filename_format => LOG_FILENAME,
:program_name => RAILS_PROGRAM_NAME,
:message_format => "--\n%l [%t] %m\n\n"
)
end
ActionLogger does a lot with format strings (like the :message_format
and :filename_format strings). This means you don''t have to create a
bunch of Formatter or Device objects as you would in log4r, you just
specify a few strings in the configuration hash and off you go.
ActionLogger is supposed to be smart enough to figure out the internal
implementation.
Also ActionLogger has automatic fall back to standard out if it can''t
log to the filename specified in the :filename_format string.
--
John