# AR and Logger

**URL:** <https://www.ruby-forum.com/t/ar-and-logger/105068>\
**Category:** Rails\
**Created:** [May 25, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/ar-and-logger/105068 "2007-05-25T14:24:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [May 25, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/ar-and-logger/105068/1 "2007-05-25T14:24:54Z")

</div>

I posted a minor rave in ruby-talk about the intrussiveness of AR with  
the Logger implementation.  
The original describes how I use a Formatter to get the desired message  
format and how it all goes awry when I require AR.

It has been very annoying (to the point of considering dropping AR  
altogether).  
I finally found the culprit (it’s in active\_support/clean\_logger.rb):

alias old\_format\_message format\_message

# Ruby 1.8.3 transposed the msg and progname arguments to

format\_message.

# We can’t test RUBY\_VERSION because some distributions don’t keep Ruby

# and its standard library in sync, leading to installations of Ruby

1.8.2

# with Logger from 1.8.3 and vice versa.

if method\_defined?(:formatter=)  
def format\_message(severity, timestamp, progname, msg)  
“#{msg}\n”  
end  
else  
def format\_message(severity, timestamp, msg, progname)  
“#{msg}\n”  
end  
end

Now, apart from the reservation I have about hacking a base library like  
Logger, I also wonder why would one overwrite the newer (1.8.3)  
format\_message implementation although Logger now allows for a format  
definition.

Why not use the following:  
if !method\_defined?(:formatter=)  
def format\_message(severity, timestamp, progname, msg)  
“#{msg}\n”  
end  
end

Then create an ActiveRecordFormatter

class ActiveRecordFormatter\<Logger::Formatter  
def call severity, time, progname, msg  
“#{msg}\n”  
end  
end

and assign this as the default\_formatter for Logger.

This is a lot less intrusive for the \>1.8.3 implementations than what we  
have at the moment.  
Cheers,  
V.-

---

<div class="post-metadata">

**Author:** ![Vassilis\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/848f3c/32.png) [@Vassilis\_R](https://www.ruby-forum.com/u/Vassilis_R)\
**Post date:** [May 25, 2007, 2:48pm UTC](https://www.ruby-forum.com/t/ar-and-logger/105068/2 "2007-05-25T14:48:28Z")

</div>

Vassilis R. wrote:

> I posted a minor rave in ruby-talk about the intrussiveness of AR with  
> the Logger implementation.  
> [snip]
> 
> and assign this as the default\_formatter for Logger.
> 
> This is a lot less intrusive for the \>1.8.3 implementations than what we  
> have at the moment.  
> Ok, I found the ticket [http://dev.rubyonrails.org/ticket/7106](http://dev.rubyonrails.org/ticket/7106) with the  
> fix I want, and it has been commited 3 months ago but did not make it  
> into activesupport 1.4.2.

Any chance for a 1.4.3 release?  
Cheers,  
V.-
