Class: Omnitest::ProjectLogger

Inherits:
Object
  • Object
show all
Includes:
Logger::Severity
Defined in:
lib/omnitest/project_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ProjectLogger

Constructs a new logger.

Parameters:

  • options (Hash) (defaults to: {})

    configuration for a new logger

Options Hash (options):

  • :color (Symbol)

    color to use when when outputting messages

  • :level (Integer)

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

  • :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: ‘“Omnitest”`)

  • :stdout (IO)

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



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omnitest/project_logger.rb', line 24

def initialize(options = {})
  color = options[:color]

  @loggers = []
  @loggers << @logdev = logdev_logger(options[:logdev]) if options[:logdev]
  @loggers << stdout_logger(options[:stdout], color) if options[:stdout]
  @loggers << stdout_logger($stdout, color) if @loggers.empty?

  self.progname = options[:progname] || 'Omnitest'
  self.level = options[:level] || default_log_level
end

Instance Attribute Details

#logdevIO (readonly)

Returns the log device.

Returns:

  • (IO)

    the log device



9
10
11
# File 'lib/omnitest/project_logger.rb', line 9

def logdev
  @logdev
end

Instance Method Details

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

Dump one or more messages to info.

Parameters:

  • message (#to_s)

    the message to log

See Also:



97
# File 'lib/omnitest/project_logger.rb', line 97

delegate_to_all_loggers :<<

#addObject

Log a message if the given severity is high enough.



91
# File 'lib/omnitest/project_logger.rb', line 91

delegate_to_all_loggers :add

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

Parameters:

  • message_or_progname (#to_s)

    the message to log. In the block form, this is the progname to use in the log message.

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.

Returns:

  • (nil, true)

    when the given severity is not high enough (for this particular logger), log no message, and return true

See Also:



110
# File 'lib/omnitest/project_logger.rb', line 110

delegate_to_all_loggers :banner

#closeObject

Close the logging devices.



218
# File 'lib/omnitest/project_logger.rb', line 218

delegate_to_all_loggers :close

#datetime_formatString

Returns the date format being used.

Returns:

  • (String)

    the date format being used

See Also:



80
# File 'lib/omnitest/project_logger.rb', line 80

delegate_to_first_logger :datetime_format

#datetime_format=Object

Sets the date format being used.

Parameters:

  • format (String)

    the date format

See Also:



86
# File 'lib/omnitest/project_logger.rb', line 86

delegate_to_all_loggers :datetime_format=

#debug { ... } ⇒ nil, true

Log a message with severity of debug.

Parameters:

  • message_or_progname (#to_s)

    the message to log. In the block form, this is the progname to use in the log message.

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.

Returns:

  • (nil, true)

    when the given severity is not high enough (for this particular logger), log no message, and return true

See Also:



123
# File 'lib/omnitest/project_logger.rb', line 123

delegate_to_all_loggers :debug

#debug?true, false

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

Returns:

  • (true, false)

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

See Also:



128
# File 'lib/omnitest/project_logger.rb', line 128

delegate_to_first_logger :debug?

#error { ... } ⇒ nil, true

Log a message with severity of error.

Parameters:

  • message_or_progname (#to_s)

    the message to log. In the block form, this is the progname to use in the log message.

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.

Returns:

  • (nil, true)

    when the given severity is not high enough (for this particular logger), log no message, and return true

See Also:



159
# File 'lib/omnitest/project_logger.rb', line 159

delegate_to_all_loggers :error

#error?true, false

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

Returns:

  • (true, false)

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

See Also:



164
# File 'lib/omnitest/project_logger.rb', line 164

delegate_to_first_logger :error?

#fatal { ... } ⇒ nil, true

Log a message with severity of fatal.

Parameters:

  • message_or_progname (#to_s)

    the message to log. In the block form, this is the progname to use in the log message.

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.

Returns:

  • (nil, true)

    when the given severity is not high enough (for this particular logger), log no message, and return true

See Also:



195
# File 'lib/omnitest/project_logger.rb', line 195

delegate_to_all_loggers :fatal

#fatal?true, false

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

Returns:

  • (true, false)

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

See Also:



200
# File 'lib/omnitest/project_logger.rb', line 200

delegate_to_first_logger :fatal?

#info { ... } ⇒ nil, true

Log a message with severity of info.

Parameters:

  • message_or_progname (#to_s)

    the message to log. In the block form, this is the progname to use in the log message.

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.

Returns:

  • (nil, true)

    when the given severity is not high enough (for this particular logger), log no message, and return true

See Also:



141
# File 'lib/omnitest/project_logger.rb', line 141

delegate_to_all_loggers :info

#info?true, false

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

Returns:

  • (true, false)

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

See Also:



146
# File 'lib/omnitest/project_logger.rb', line 146

delegate_to_first_logger :info?

#levelInteger

Returns the logging severity threshold.

Returns:

  • (Integer)

    the logging severity threshold

See Also:



60
# File 'lib/omnitest/project_logger.rb', line 60

delegate_to_first_logger :level

#level=Object

Sets the logging severity threshold.

Parameters:

  • level (Integer)

    the logging severity threshold

See Also:



66
# File 'lib/omnitest/project_logger.rb', line 66

delegate_to_all_loggers :level=

#prognameString

Returns program name to include in log messages.

Returns:

  • (String)

    program name to include in log messages

See Also:



70
# File 'lib/omnitest/project_logger.rb', line 70

delegate_to_first_logger :progname

#progname=Object

Sets the program name to include in log messages.

Parameters:

  • progname (String)

    the program name to include in log messages

See Also:



76
# File 'lib/omnitest/project_logger.rb', line 76

delegate_to_all_loggers :progname=

#unknown { ... } ⇒ nil, true

Log a message with severity of unknown.

Parameters:

  • message_or_progname (#to_s)

    the message to log. In the block form, this is the progname to use in the log message.

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.

Returns:

  • (nil, true)

    when the given severity is not high enough (for this particular logger), log no message, and return true

See Also:



213
# File 'lib/omnitest/project_logger.rb', line 213

delegate_to_all_loggers :unknown

#warn { ... } ⇒ nil, true

Log a message with severity of warn.

Parameters:

  • message_or_progname (#to_s)

    the message to log. In the block form, this is the progname to use in the log message.

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.

Returns:

  • (nil, true)

    when the given severity is not high enough (for this particular logger), log no message, and return true

See Also:



177
# File 'lib/omnitest/project_logger.rb', line 177

delegate_to_all_loggers :warn

#warn?true, false

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

Returns:

  • (true, false)

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

See Also:



182
# File 'lib/omnitest/project_logger.rb', line 182

delegate_to_first_logger :warn?