From: Tim Pease Date: 2007-07-17T23:54:12+09:00 Subject: Re: log4r configuration: "/dev/null" outputter question On 7/17/07, Ronald Fischer wrote: > > The problem is what outputter to use to implement 'none'. My first idea > to simply use FileOutputter('none',:filename => '/dev/null') does not > work > because my code is also supposed to run onder Windows where we don't > have > /dev/null. There is a /dev/null equivalent on Windows, NUL: You can use it in this fashion ... fn = test(?e, '/dev/null') ? '/dev/null' : 'NUL:' fd = File.open(fn, 'w') You can now write to that file descriptor and everything will go to the bit bucket. > > My solution works, but I wonder whether I could make it simpler > (i.e. without creating the NullOutputter class). > Certainly. Just create an instance of Outputter and then define the methods you need. out = Outputter.new 'tfwnull' class << out def canonical_log(logevent) nil end end The canonical_log method is used by the outputters to format the log event and then write the formatted output to a file. By setting this to have a nil body, you will save a few cycles each time a log messages needs to be generated. Another options is just to set the global log level to 'off'. That is left as an exercise for the reader ;-) Blessings, TwP