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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Jun 27, 2011 at 4:04 PM, giorgio <george.peverell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Basically I just want to see the Date and time on each line of the log. > > Surely it must be easy? I''m surprised its not default behaviour...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, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.