Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Active Record messes with my Logger
Vassilis Rizopoulos
12/1/2006 2:26:00 PM
Yes, I know about the hack that AR uses to make the Logger format
friendlier.
The thing is it imposes it's idea of friendliness in a global scale (as
I remember it was necessary with the 1.8.2 Logger due to the rigidness
of the format). This seriously gets on my nerves.
How can I reinstate my Logger format and apply it to active record?
It is and it's not really a Rails question, as I only use AR :)
Cheers,
V.-
--
http://www.braveworl...
2 Answers
Florian Aßmann
2/26/2007 5:20:00 PM
0
# I found no clean sollution, but maybe this can help ya:
#
begin
define = 'def format_message severity, timestamp, program_name,
message'
default = '( @formatter || @default_formatter ).call ' +
'severity, timestamp, program_name, message'
format ||= default
Logger.class_eval [ define, format, 'end' ].join('; ')
end
#
# You can define format beforehand to something like '"#
{ timestamp }: message"'
# Per default it's overwritten with Logger.format_message method
#
# Cheers
# Flo
Am 01.12.2006 um 15:26 schrieb Damphyr:
> Yes, I know about the hack that AR uses to make the Logger format
> friendlier.
> The thing is it imposes it's idea of friendliness in a global scale
> (as I remember it was necessary with the 1.8.2 Logger due to the
> rigidness of the format). This seriously gets on my nerves.
>
> How can I reinstate my Logger format and apply it to active record?
> It is and it's not really a Rails question, as I only use AR :)
> Cheers,
> V.-
>
> --
>
http://www.braveworl...
>
Vassilis Rizopoulos
3/10/2007 7:00:00 AM
0
Florian Aßmann wrote:
> # I found no clean sollution, but maybe this can help ya:
> #
> begin
> define = 'def format_message severity, timestamp, program_name,
> message'
> default = '( @formatter || @default_formatter ).call ' +
> 'severity, timestamp, program_name, message'
>
> format ||= default
>
> Logger.class_eval [ define, format, 'end' ].join('; ')
> end
> #
> # You can define format beforehand to something like '"#{ timestamp }:
> message"'
> # Per default it's overwritten with Logger.format_message method
> #
> # Cheers
> # Flo
Oh, I found a much cleaner solution:
class MyLogFormatter<Logger::Formatter
MyLogFormat = "[%s] %5s -- %s: %s\n"
def call severity,time,progname,msg
MyLogFormat % [format_datetime(time), severity, progname,
msg2str(msg)]
end
end
logger.formatter=MyLogFormatter.new
logger.formatter.datetime_format="%Y%m%d %H:%M:%S"
It's not exactly documented (at least the RDoc in ruby-doc stil contains
the comment about having to hack the Format constant). This way you can
play with the format constant used and not mess with the logger internals.
Cheers,
V.-
--
http://www.braveworl...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Active Record messes with my Logger
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password