Active Record messes with my Logger

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 :slight_smile:
Cheers,
V.-

···

--
http://www.braveworld.net/riva

# 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 :slight_smile:
Cheers,
V.-

--
http://www.braveworld.net/riva

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.braveworld.net/riva