Hi all,
I’m trying to use log4r ( Log4r - Contact )
but when running the example given at the site, I get an error (and I
would like to know what I could do about it)
The example is like so (from the abovementioned web page):
require ‘log4r’
include Log4r
create a logger named ‘mylog’ that logs to stdout
mylog = Logger.new ‘mylog’
mylog.outputters = Outputter.stdout
Now we can log.
def do_log(log)
log.debug “This is a message with level DEBUG”
log.info “This is a message with level INFO”
log.warn “This is a message with level WARN”
log.error “This is a message with level ERROR”
log.fatal “This is a message with level FATAL”
end
do_log(mylog)
Now, the should be this:
DEBUG mylog: This is a message with level DEBUG
INFO mylog: This is a message with level INFO
WARN mylog: This is a message with level WARN
ERROR mylog: This is a message with level ERROR
FATAL mylog: This is a message with level FATAL
…but I get that:
C:/RUBY/lib/ruby/site_ruby/1.8/log4r/formatter/formatter.rb:58:in
sprintf': unnumbered(1) mixed with numbered (ArgumentError) from C:/RUBY/lib/ruby/site_ruby/1.8/log4r/formatter/formatter.rb:58:in
format’
from C:/RUBY/lib/ruby/site_ruby/1.8/log4r/outputter/outputter.rb:118:in
format' from C:/RUBY/lib/ruby/site_ruby/1.8/log4r/outputter/outputter.rb:108:in
canonical_log’
from C:/RUBY/lib/ruby/site_ruby/1.8/log4r/outputter/outputter.rb:108:in
synch' from C:/RUBY/lib/ruby/site_ruby/1.8/log4r/outputter/outputter.rb:128:in
synchronize’
from C:/RUBY/lib/ruby/site_ruby/1.8/log4r/outputter/outputter.rb:128:in
synch' from C:/RUBY/lib/ruby/site_ruby/1.8/log4r/outputter/outputter.rb:108:in
canonical_log’
from (eval):3:in debug' from (eval):8:in
debug’
from (eval):8:in each' from (eval):8:in
debug’
from C:/Stephan/Programmierung/WegwerfSkripte/log4r.rb:12:in `do_log’
from C:/Stephan/Programmierung/WegwerfSkripte/log4r.rb:18
Now I admit I’m quite not used to using sprintf…
Any ideas?
Cheers
Stephan
Stephan Kämper wrote:
C:/RUBY/lib/ruby/site_ruby/1.8/log4r/formatter/formatter.rb:58:in
`sprintf’: unnumbered(1) mixed with numbered (ArgumentError)
It has to do with how the author of Log4r implemented his sprintfs.
Apparently you can number your parameters or not, but you can’t mix them:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/663
In this case, the solution is to change this:
class SimpleFormatter < Formatter
@@simpleformat = “%*4$s %s> %s\n”
def format(event)
sprintf @@simpleformat, LNAMES[event.level],
event.name, event.data, MaxLevelLength
end
end
to this:
class SimpleFormatter < Formatter
@@simpleformat = “%*4$1$s %2$s> %3$s\n”
def format(event)
sprintf @@simpleformat, LNAMES[event.level],
event.name, event.data, MaxLevelLength
end
end
and this:
class BasicFormatter < SimpleFormatter
@@basicformat = “%*3$s %s”
to this:
class BasicFormatter < SimpleFormatter
@@basicformat = “%*3$1$s %2$s”
in log4r/formatter/formatter.rb
I’m not sure if the author is still actively maintaining Log4r, but if
he is, someone should ask him to update this, as well as start using
#class rather than #type. His code spits out a lot of warnings because
of this.
Ben
Stephan Kämper wrote:
C:/RUBY/lib/ruby/site_ruby/1.8/log4r/formatter/formatter.rb:58:in
`sprintf’: unnumbered(1) mixed with numbered (ArgumentError)
I’m not sure if the author is still actively maintaining Log4r, but if
he is, someone should ask him to update this, as well as start using
#class rather than #type. His code spits out a lot of warnings because
of this.
Ben
I got in contact with Leon Torres, the author of log4r, a couple of days
ago. He’s in the process of fixing this problem and making some other
changes before making a new release.
It’d be good to see this package in the standard distro as it’s an
excellent logger.
regards,
Martin
martins@aardvark.net.au wrote in message news:43684.203.22.14.128.1062112904.squirrel@www.aardvark.net.au…
Stephan Kämper wrote:
C:/RUBY/lib/ruby/site_ruby/1.8/log4r/formatter/formatter.rb:58:in
`sprintf’: unnumbered(1) mixed with numbered (ArgumentError)
I’m not sure if the author is still actively maintaining Log4r, but if
he is, someone should ask him to update this, as well as start using
#class rather than #type. His code spits out a lot of warnings because
of this.
Ben
I got in contact with Leon Torres, the author of log4r, a couple of days
ago. He’s in the process of fixing this problem and making some other
changes before making a new release.
That’s good news. For anyone in a hurry, I posted a patch for this
problem about 6 months ago:
Log4r - Logging system written in Ruby download | SourceForge.net
There’s also my simple cut at a SyslogOutputter.
It’d be good to see this package in the standard distro as it’s an
excellent logger.
It would be really nice to have SOME logger included, but of course it
would need to be maintained 
Steve
···
regards,
Martin
Hi folks, I apologize for falling off the face of the Earth and not keeping
log4r up to date with Ruby. I no longer code for a living, so my interest
has faltered. Such a shame too because Ruby was pleasant to code in. 
If anyone wishes to become the primary maintainer for log4r, please contact
me. It’s a very basic library and not much work. Please adopt log4r!
It’d be good to see this package in the standard distro as it’s an
excellent logger.
It would be really nice to have SOME logger included, but of course it
would need to be maintained 
Yeah, it would. 
Cheers,
Leon