Basically I just want to see the Date and time on each line of the
log.
I cant seem to find out how to do that.
Surely it must be easy? I'm surprised its not default behaviour...
I am running Rails 2.2.2
Cheers
George
Basically I just want to see the Date and time on each line of the
log.
I cant seem to find out how to do that.
Surely it must be easy? I'm surprised its not default behaviour...
I am running Rails 2.2.2
Cheers
George
I am too, but ...
For a 2.3.x app, I just overrode ActiveSupport::BufferedLogger#add
to put the timestamp at the beginning of the line. Still seems vaguely
hacky, but it works just fine.
HTH,
Overriding ActiveSupport::BufferedLogger#add seesm to be the way to
go.
I found the following on StackOverflow and stuck it at the bottom of
Envioronment.rb and it seems to work well.
I'm amazed the standard logger does not do thios!
module ActiveSupport
class BufferedLogger
def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = (message || (block && block.call) || progname).to_s
level = {
0 => "DEBUG",
1 => "INFO ",
2 => "WARN ",
3 => "ERROR",
4 => "FATAL"
}[severity] || "U"
message = "[%s: %s] %s" % [level,Time.now.strftime("%Y-%m-%d %H:
%M:%S"), message]
message = "#{message}\n" unless message[-1] == ?\n
buffer << message
auto_flush
message
end
end