Module: CountingSemaphore::NullLogger

Extended by:
NullLogger
Included in:
NullLogger
Defined in:
lib/counting_semaphore/null_logger.rb

Overview

A null logger that discards all log messages. Provides the same interface as a real logger but does nothing. Only yields blocks when ENV is set to “yes”, which is useful in testing. Block form for Logger calls allows you to skip block evaluation if the Logger level is higher than your call, and thus bugs can nest in those Logger blocks. During testing it is helpful to excercise those blocks unconditionally.

Instance Method Summary collapse

Instance Method Details

#debug(message = nil) { ... } ⇒ nil

Logs a debug message. Discards the message but may yield the block for testing.

Parameters:

  • message (String, nil) (defaults to: nil)

    Optional message to log (discarded)

Yields:

  • Optional block that will only be executed if ENV == “yes”

Returns:

  • (nil)


17
18
19
# File 'lib/counting_semaphore/null_logger.rb', line 17

def debug(message = nil, &block)
  yield if block_given? && ENV["RUN_ALL_LOGGER_BLOCKS"] == "yes"
end

#error(message = nil) { ... } ⇒ nil

Logs an error message. Discards the message but may yield the block for testing.

Parameters:

  • message (String, nil) (defaults to: nil)

    Optional message to log (discarded)

Yields:

  • Optional block that will only be executed if ENV == “yes”

Returns:

  • (nil)


44
45
46
# File 'lib/counting_semaphore/null_logger.rb', line 44

def error(message = nil, &block)
  yield if block_given? && ENV["RUN_ALL_LOGGER_BLOCKS"] == "yes"
end

#fatal(message = nil) { ... } ⇒ nil

Logs a fatal message. Discards the message but may yield the block for testing.

Parameters:

  • message (String, nil) (defaults to: nil)

    Optional message to log (discarded)

Yields:

  • Optional block that will only be executed if ENV == “yes”

Returns:

  • (nil)


53
54
55
# File 'lib/counting_semaphore/null_logger.rb', line 53

def fatal(message = nil, &block)
  yield if block_given? && ENV["RUN_ALL_LOGGER_BLOCKS"] == "yes"
end

#info(message = nil) { ... } ⇒ nil

Logs an info message. Discards the message but may yield the block for testing.

Parameters:

  • message (String, nil) (defaults to: nil)

    Optional message to log (discarded)

Yields:

  • Optional block that will only be executed if ENV == “yes”

Returns:

  • (nil)


26
27
28
# File 'lib/counting_semaphore/null_logger.rb', line 26

def info(message = nil, &block)
  yield if block_given? && ENV["RUN_ALL_LOGGER_BLOCKS"] == "yes"
end

#warn(message = nil) { ... } ⇒ nil

Logs a warning message. Discards the message but may yield the block for testing.

Parameters:

  • message (String, nil) (defaults to: nil)

    Optional message to log (discarded)

Yields:

  • Optional block that will only be executed if ENV == “yes”

Returns:

  • (nil)


35
36
37
# File 'lib/counting_semaphore/null_logger.rb', line 35

def warn(message = nil, &block)
  yield if block_given? && ENV["RUN_ALL_LOGGER_BLOCKS"] == "yes"
end