# Using logger

**URL:** <https://www.ruby-forum.com/t/using-logger/95138>\
**Category:** Ruby\
**Created:** [November 13, 2005, 11:47pm UTC](https://www.ruby-forum.com/t/using-logger/95138 "2005-11-13T23:47:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 13, 2005, 11:47pm UTC](https://www.ruby-forum.com/t/using-logger/95138/1 "2005-11-13T23:47:32Z")

</div>

Hi. I’m trying to use Ruby’s built in logger to show messages with the  
severity and timestamp, but I’m just getting the message string, (no  
severity or timestamp).

Any suggestions?

(If possible, please cc all responses to me at listrecv at gmail,  
thanks!)

> > l=Logger.new(STDOUT)  
> > =\> #\<Logger:0x5a04910 @progname=nil,  
> > @logdev=#\<Logger::LogDevice:0x5a048b0 @dev=  
> > #IO:0x48ce7e8, @shift\_size=nil, @shift\_age=nil, @filename=nil\>,  
> > @level=0, @dat  
> > etime\_format=nil\>
> 
> > l.info ‘Test’  
> > Test  
> > =\> true
> 
> > l.formatter = proc { |s, t, p, m| “#{s} #{t} #{p} #{m}” }  
> > NoMethodError: undefined method `formatter=’ for #Logger:0x5a04910  
> > from (irb):138  
> > from :0
> 
> > l.info ‘try again’  
> > try again  
> > =\> true

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 14, 2005, 2:05am UTC](https://www.ruby-forum.com/t/using-logger/95138/2 "2005-11-14T02:05:44Z")

</div>

On Mon, 14 Nov 2005 removed\_email\_address@domain.invalid wrote:

> =\> #\<Logger:0x5a04910 @progname=nil,  
> from :0
> 
> > > l.info ‘try again’  
> > > try again  
> > > =\> true
> > 
> > >

which ruby version? this certainly works for me:

harp:~ \> ruby -r logger -e’ Logger::new(STDOUT).info 42 ’  
I, [2005-11-13T17:51:50.496175 #5158] INFO – : 42

harp:~ \> ruby -r logger -e’ Logger::new(STDOUT).info{ 42 } ’  
I, [2005-11-13T17:51:57.527556 #5159] INFO – : 42

-a

---

<div class="post-metadata">

**Author:** ![listrecv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f17d59/32.png) [@listrecv](https://www.ruby-forum.com/u/listrecv)\
**Post date:** [November 14, 2005, 12:49pm UTC](https://www.ruby-forum.com/t/using-logger/95138/3 "2005-11-14T12:49:45Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi,

Ara.T.Howard wrote:

> > Hi. I’m trying to use Ruby’s built in logger to show messages with the  
> > severity and timestamp, but I’m just getting the message string, (no  
> > severity or timestamp).

> which ruby version? this certainly works for me:

It should be ruby-1.8.2 or earlier. Logger#formatter= is from  
ruby-1.8.3.

Unfortunately some library/application ruins original logger.rb.  
Adding the following line may recover the original logger.rb definition  
(with some warnings).

load “logger.rb”

Regards,  
// NaHi  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.1 (Cygwin)

iD8DBQFDeHj6f6b33ts2dPkRAg7yAJ97Zsd+mhYacOioWU52e/LdhFsZQwCcCGJI  
n/PJY4kT6tJ8/h805Qlis64=  
=fxOa  
-----END PGP SIGNATURE-----
