1. 5
  1.  

  2. 6

    Meanwhile in Ruby-land the logger API allows the message to be passed in a block (i.e. a lambda) to avoid eager evaluation:

    Always evaluated:

    logger.debug("total number: #{get_object_counts()}")
    

    Evaluated only is debug level >= DEBUG:

    logger.debug {"total number: #{get_object_counts()}" }
    

    This well-thought API makes the logging statements stand out less. (And is part of the stdlib.)

    1. 4

      In my experience it’s better just to check logger.isEnabledFor(DEBUG) before the whole statement rather than to be clever in the way described