Class: Kitchen::Logger

Inherits:
Object
  • Object
show all
Includes:
Logger::Severity
Defined in:
lib/kitchen/logger.rb

Overview

Logging implementation for Kitchen. By default the console/stdout output will be displayed differently than the file log output. Therefor, this class wraps multiple loggers that conform to the stdlib ‘Logger` class behavior.

Defined Under Namespace

Classes: LogdevLogger, StdoutLogger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Logger

Constructs a new logger.

Options Hash (options):

  • :color (Symbol)

    color to use when when outputting messages

  • :level (Integer)

    the logging severity threshold (default: ‘Kitchen::DEFAULT_LOG_LEVEL`)

  • whether (Boolean)

    to overwrite the log when Test Kitchen runs. Only applies if the :logdev is a String. (default: ‘Kitchen::DEFAULT_LOG_OVERWRITE`)

  • :logdev (String, IO)

    filepath String or IO object to be used for logging (default: ‘nil`)

  • :progname (String)

    program name to include in log messages (default: ‘“Kitchen”`)

  • :stdout (IO)

    a standard out IO object to use (default: ‘$stdout`)

  • :colorize (Boolean)

    whether to colorize output when Test Kitchen runs. (default: ‘$stdout.tty?`)



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kitchen/logger.rb', line 57

def initialize(options = {})
  @log_overwrite = if options[:log_overwrite].nil?
                     default_log_overwrite
                   else
                     options[:log_overwrite]
                   end

  @logdev = logdev_logger(options[:logdev], log_overwrite) if options[:logdev]

  populate_loggers(options)

  # These setters cannot be called until @loggers are populated because
  # they are delegated
  self.progname = options[:progname] || "Kitchen"
  self.level = options[:level] || default_log_level
end

Instance Attribute Details

#log_overwriteBoolean (readonly)



36
37
38
# File 'lib/kitchen/logger.rb', line 36

def log_overwrite
  @log_overwrite
end

#logdevIO (readonly)



32
33
34
# File 'lib/kitchen/logger.rb', line 32

def logdev
  @logdev
end

Instance Method Details

#:<<(: <<()) ⇒ Object

Dump one or more messages to info.



148
# File 'lib/kitchen/logger.rb', line 148

delegate_to_all_loggers :<<

#addObject

Log a message if the given severity is high enough.



142
# File 'lib/kitchen/logger.rb', line 142

delegate_to_all_loggers :add

Log a message with severity of banner (high level).

Yields:

  • evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

See Also:



161
# File 'lib/kitchen/logger.rb', line 161

delegate_to_all_loggers :banner

#closeObject

Close the logging devices.



269
# File 'lib/kitchen/logger.rb', line 269

delegate_to_all_loggers :close

#datetime_formatString

Returns the date format being used.



131
# File 'lib/kitchen/logger.rb', line 131

delegate_to_first_logger :datetime_format

#datetime_format=Object

Sets the date format being used.



137
# File 'lib/kitchen/logger.rb', line 137

delegate_to_all_loggers :datetime_format=

#debug { ... } ⇒ nil, true

Log a message with severity of debug.

Yields:

  • evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

See Also:



174
# File 'lib/kitchen/logger.rb', line 174

delegate_to_all_loggers :debug

#debug?true, false

Returns whether or not the current severity level allows for the printing of debug messages.



179
# File 'lib/kitchen/logger.rb', line 179

delegate_to_first_logger :debug?

#error { ... } ⇒ nil, true

Log a message with severity of error.

Yields:

  • evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

See Also:



210
# File 'lib/kitchen/logger.rb', line 210

delegate_to_all_loggers :error

#error?true, false

Returns whether or not the current severity level allows for the printing of error messages.



215
# File 'lib/kitchen/logger.rb', line 215

delegate_to_first_logger :error?

#fatal { ... } ⇒ nil, true

Log a message with severity of fatal.

Yields:

  • evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

See Also:



246
# File 'lib/kitchen/logger.rb', line 246

delegate_to_all_loggers :fatal

#fatal?true, false

Returns whether or not the current severity level allows for the printing of fatal messages.



251
# File 'lib/kitchen/logger.rb', line 251

delegate_to_first_logger :fatal?

#info { ... } ⇒ nil, true

Log a message with severity of info.

Yields:

  • evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

See Also:



192
# File 'lib/kitchen/logger.rb', line 192

delegate_to_all_loggers :info

#info?true, false

Returns whether or not the current severity level allows for the printing of info messages.



197
# File 'lib/kitchen/logger.rb', line 197

delegate_to_first_logger :info?

#levelInteger

Returns the logging severity threshold.



111
# File 'lib/kitchen/logger.rb', line 111

delegate_to_first_logger :level

#level=Object

Sets the logging severity threshold.



117
# File 'lib/kitchen/logger.rb', line 117

delegate_to_all_loggers :level=

#prognameString

Returns program name to include in log messages.



121
# File 'lib/kitchen/logger.rb', line 121

delegate_to_first_logger :progname

#progname=Object

Sets the program name to include in log messages.



127
# File 'lib/kitchen/logger.rb', line 127

delegate_to_all_loggers :progname=

#unknown { ... } ⇒ nil, true

Log a message with severity of unknown.

Yields:

  • evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

See Also:



264
# File 'lib/kitchen/logger.rb', line 264

delegate_to_all_loggers :unknown

#warn { ... } ⇒ nil, true

Log a message with severity of warn.

Yields:

  • evaluates to the message to log. This is not evaluated unless the logger’s level is sufficient to log the message. This allows you to create potentially expensive logging messages that are only called when the logger is configured to show them.

See Also:



228
# File 'lib/kitchen/logger.rb', line 228

delegate_to_all_loggers :warn

#warn?true, false

Returns whether or not the current severity level allows for the printing of warn messages.



233
# File 'lib/kitchen/logger.rb', line 233

delegate_to_first_logger :warn?