# Active Record messes with my Logger

**URL:** <https://www.ruby-forum.com/t/active-record-messes-with-my-logger/77913>\
**Category:** Ruby\
**Created:** [December 1, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/active-record-messes-with-my-logger/77913 "2006-12-01T15:28:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 1, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/active-record-messes-with-my-logger/77913/1 "2006-12-01T15:28:06Z")

</div>

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.-

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 26, 2007, 6:20pm UTC](https://www.ruby-forum.com/t/active-record-messes-with-my-logger/77913/2 "2007-02-26T18:20:26Z")

</div>

# 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:

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 10, 2007, 8:01am UTC](https://www.ruby-forum.com/t/active-record-messes-with-my-logger/77913/3 "2007-03-10T08:01:05Z")

</div>

Florian Aßmann wrote:

> 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.-
