Sending false to logger outputs nil?


#1

Am I missing something? Why would sending false to the logger just
output nil, instead of “false” to correspond to what sending true
does?

According to the docs: "message can be any object, but it has to be
converted to a String in order to log it. Generally, inspect is used
if the given object is not a String. "

This just drove me crazy for a good half hour until I figured out what
was going on, as I was logging a complex statement that evaluated to a
boolean…

irb(main):001:0> require ‘logger’

=> true
irb(main):002:0> logger = Logger.new(STDOUT)
=> #<Logger:0x3307f0 @level=0, @progname=nil,
@logdev=#<Logger::LogDevice:0x3307a0 @dev=#IO:0x1e9868,
@shift_size=nil, @shift_age=nil, @filename=nil,
@mutex=#<Logger::LogDevice::LogDeviceMutex:0x330778
@mon_waiting_queue=[], @mon_entering_queue=[], @mon_count=0,
@mon_owner=nil>>, @formatter=nil,
@default_formatter=#<Logger::Formatter:0x3307c8 @datetime_format=nil>>

irb(main):003:0> logger.debug(true)
D, [2006-06-07T16:10:23.569265 #5516] DEBUG – : true
=> true

irb(main):004:0> logger.debug(false)
D, [2006-06-07T16:10:26.721498 #5516] DEBUG – : nil
=> true

irb(main):005:0> logger.info(false)
I, [2006-06-07T16:10:59.451009 #5516] INFO – : nil
=> true

  • Rob