I'm writing an application that uses both Ruby's Logger and
ActiveRecord, but ActiveRecord seems to break Ruby's Logger, as
the Logger data (date, level, etc...) is not output anymore.
I'm writing an application that uses both Ruby's Logger and
ActiveRecord, but ActiveRecord seems to break Ruby's Logger, as
the Logger data (date, level, etc...) is not output anymore.
Hi George
Rails' ActiveSupport overrides the Logger#format_message method. To
get back to the normal log formatting, you can use something like this
in you script.
class Logger
private
# Rails overrides this method so that it can customize the format
# of it's logs.
def format_message(*args)
old_format_message(*args)
end
end
Which is a bit hacky maybe, but it's working for me at the moment.
I'm writing an application that uses both Ruby's Logger and
ActiveRecord, but ActiveRecord seems to break Ruby's Logger, as
the Logger data (date, level, etc...) is not output anymore.
Below is an example: [code snipped]
$ ruby testlog.rb
Hello, world!
versus
$ ruby testlog2.rb
I, [2006-07-12T18:26:13.556000 #4228] INFO -- : Hello, world!
To make it normal, I have to load "logger" after require_gem
"activerecord" (with warning messages output)...
What do I miss?
I think Rails defines a class called Logger which must be clobbering
the standard one.
> I'm writing an application that uses both Ruby's Logger and
> ActiveRecord, but ActiveRecord seems to break Ruby's Logger, as
> the Logger data (date, level, etc...) is not output anymore.
Hi George
Rails' ActiveSupport overrides the Logger#format_message method. To
get back to the normal log formatting, you can use something like this
in you script.
class Logger
private
# Rails overrides this method so that it can customize the format
# of it's logs.
def format_message(*args)
old_format_message(*args)
end
end
Nick,
Funny, I was just having this same problem with Logger and ActiveRecord. I
can't seem to get your solution to work.
class Logger
private
# Rails overrides this method so that it can customize the format
# of it's logs.
def format_message(*args)
old_format_message(*args)
end
end
log = Logger.new(STDERR)
log.info("Hello!")
Throws this error:
/home/neilk/bin/loggertest.rb:14:in `format_message': undefined method
`old_format_message' for #<Logger:0x489cc8> (NoMethodError)
from /ropt/local/lib/ruby/1.8/logger.rb:320:in `add'
from /ropt/local/lib/ruby/1.8/logger.rb:372:in `info'
from /home/neilk/bin/loggertest.rb:21