Frederick Cheung wrote:
> probably because activerecord requires activesupport and activesupport
> does
> 
> http://github.com/rails/rails/blob/669fd84910586d4c791b6f5bf4320f68ac7845aa/activesupport/lib/active_support/core_ext/logger.rb
> 

For what it's worth, I share the original questioners general 
unhappiness with Rails default logging format.

It's possible to customize that without too much code, although somewhat 
more confusing and under-documented than one might wish, and also seems 
to change slightly from one Rails version to the next, for whatever 
reasons the precise hooks into Rails logging mechanisms seem to be 
somewhat unstable.

Here's how I customize logging in a Rails 2.1.2 app, choosing to use the 
Rails2 default "BuferredLogger" for what (I assume) is better efficiency 
in disk writes, but with my own output formats.  Anyone feel free to let 
me know if there's a better way, or if this is easier in subsequent 
Rails versions. But it's not too hard (once you figure it out, which 
took me a bit of playing around).

In my lib directory, a sub-class of the BufferedLogger that actually 
accepts a formatter, as the standard BufferedLogger (at least in 2.1.1) 
oddly does not:

http://umlaut.rubyforge.org/svn/trunk/lib/umlaut_logger.rb

Then in environment.rb, set the logger and it's formatter:

    require_dependency 'umlaut_logger'
    severity_level = 
ActiveSupport::BufferedLogger.const_get(config.log_level.to_s.upcase)
    log_file = File.join(RAILS_ROOT, "log", "#{RAILS_ENV}.log")

    our_logger = UmlautLogger.new(log_file, severity_level)
    our_logger.formatter = lambda do |severity_label, msg|
      time_fmtd = Time.now.strftime("%d %b %H:%M:%S")
      preface = "[#{time_fmtd}] (pid:#{$$}) #{severity_label}: "
      # stick our preface AFTER any initial newlines
      msg =~ /^(\n+)[^\n]/
      index = $1 ? $1.length : 0
      return msg.insert(index, preface)
    end
    config.logger = our_logger

-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to