Class: Kitchen::Logger
- Inherits:
-
Object
- Object
- Kitchen::Logger
- 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. Therefore, this
class wraps multiple loggers that conform to the stdlib Logger class
behavior.
Defined Under Namespace
Classes: DeviceFactory, LineBuffer, LogdevLogger, SinkSet, StdoutLogger, StreamLineFormatter, StructuredLogdevLogger
Instance Attribute Summary collapse
-
#log_overwrite ⇒ Boolean
readonly
Whether logger is configured for overwriting.
-
#logdev ⇒ IO
readonly
The log device.
-
#logdev_path ⇒ String?
readonly
The expanded text log path, if configured.
-
#structured_logdev ⇒ IO
readonly
The structured log device.
-
#structured_logdev_path ⇒ String?
readonly
The expanded structured log path, if configured.
Instance Method Summary collapse
-
#<<(message) ⇒ Object
Dump one or more messages to info.
-
#add(severity, message = nil, progname = nil) { ... } ⇒ Object
Log a message if the given severity is high enough.
-
#banner(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of banner (high level).
-
#close ⇒ Object
Close the logging devices.
-
#datetime_format ⇒ String
The date format being used.
-
#datetime_format=(format) ⇒ Object
Sets the date format being used.
-
#debug(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of debug.
-
#debug? ⇒ true, false
Whether or not the current severity level allows for the printing of debug messages.
-
#error(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of error.
-
#error? ⇒ true, false
Whether or not the current severity level allows for the printing of error messages.
-
#fatal(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of fatal.
-
#fatal? ⇒ true, false
Whether or not the current severity level allows for the printing of fatal messages.
-
#info(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of info.
-
#info? ⇒ true, false
Whether or not the current severity level allows for the printing of info messages.
-
#initialize(options = {}) ⇒ Logger
constructor
Constructs a new logger.
-
#level ⇒ Integer
The logging severity threshold.
-
#level=(level) ⇒ Object
Sets the logging severity threshold.
-
#metadata ⇒ Hash
Metadata added to structured log events.
-
#progname ⇒ String
Program name to include in log messages.
-
#progname=(progname) ⇒ Object
Sets the program name to include in log messages.
-
#unknown(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of unknown.
-
#warn(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of warn.
-
#warn? ⇒ true, false
Whether or not the current severity level allows for the printing of warn messages.
-
#with_metadata(values) ⇒ Object
Temporarily adds metadata to structured log events.
Constructor Details
#initialize(options = {}) ⇒ Logger
Constructs a new logger.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kitchen/logger.rb', line 68 def initialize( = {}) @base_metadata = [:metadata] || {} @log_overwrite = if [:log_overwrite].nil? default_log_overwrite else [:log_overwrite] end @logdev = device_factory.logdev_logger([:logdev], log_overwrite) if [:logdev] if [:structured_logdev] @structured_logdev = device_factory.structured_logdev_logger( [:structured_logdev], log_overwrite, -> { } ) end @logdev_path = ([:logdev]) @structured_logdev_path = ([:structured_logdev]) populate_loggers() # These setters cannot be called until @loggers are populated because # they are delegated self.progname = [:progname] || "Kitchen" self.level = [:level] || default_log_level end |
Instance Attribute Details
#log_overwrite ⇒ Boolean (readonly)
Returns whether logger is configured for overwriting.
47 48 49 |
# File 'lib/kitchen/logger.rb', line 47 def log_overwrite @log_overwrite end |
#logdev ⇒ IO (readonly)
Returns the log device.
34 35 36 |
# File 'lib/kitchen/logger.rb', line 34 def logdev @logdev end |
#logdev_path ⇒ String? (readonly)
Returns the expanded text log path, if configured.
40 41 42 |
# File 'lib/kitchen/logger.rb', line 40 def logdev_path @logdev_path end |
#structured_logdev ⇒ IO (readonly)
Returns the structured log device.
37 38 39 |
# File 'lib/kitchen/logger.rb', line 37 def structured_logdev @structured_logdev end |
#structured_logdev_path ⇒ String? (readonly)
Returns the expanded structured log path, if configured.
43 44 45 |
# File 'lib/kitchen/logger.rb', line 43 def structured_logdev_path @structured_logdev_path end |
Instance Method Details
#<<(message) ⇒ Object
Dump one or more messages to info.
177 |
# File 'lib/kitchen/logger.rb', line 177 delegate_to_all_loggers :<< |
#add(severity, message = nil, progname = nil) { ... } ⇒ Object
Log a message if the given severity is high enough.
170 |
# File 'lib/kitchen/logger.rb', line 170 delegate_to_all_loggers :add |
#banner(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of banner (high level).
191 |
# File 'lib/kitchen/logger.rb', line 191 delegate_to_all_loggers :banner |
#close ⇒ Object
Close the logging devices.
311 |
# File 'lib/kitchen/logger.rb', line 311 delegate_to_all_loggers :close |
#datetime_format ⇒ String
Returns the date format being used.
151 |
# File 'lib/kitchen/logger.rb', line 151 delegate_to_first_logger :datetime_format |
#datetime_format=(format) ⇒ Object
Sets the date format being used.
158 |
# File 'lib/kitchen/logger.rb', line 158 delegate_to_all_loggers :datetime_format= |
#debug(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of debug.
205 |
# File 'lib/kitchen/logger.rb', line 205 delegate_to_all_loggers :debug |
#debug? ⇒ true, false
Returns whether or not the current severity level allows for the printing of debug messages.
211 |
# File 'lib/kitchen/logger.rb', line 211 delegate_to_first_logger :debug? |
#error(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of error.
245 |
# File 'lib/kitchen/logger.rb', line 245 delegate_to_all_loggers :error |
#error? ⇒ true, false
Returns whether or not the current severity level allows for the printing of error messages.
251 |
# File 'lib/kitchen/logger.rb', line 251 delegate_to_first_logger :error? |
#fatal(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of fatal.
285 |
# File 'lib/kitchen/logger.rb', line 285 delegate_to_all_loggers :fatal |
#fatal? ⇒ true, false
Returns whether or not the current severity level allows for the printing of fatal messages.
291 |
# File 'lib/kitchen/logger.rb', line 291 delegate_to_first_logger :fatal? |
#info(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of info.
225 |
# File 'lib/kitchen/logger.rb', line 225 delegate_to_all_loggers :info |
#info? ⇒ true, false
Returns whether or not the current severity level allows for the printing of info messages.
231 |
# File 'lib/kitchen/logger.rb', line 231 delegate_to_first_logger :info? |
#level ⇒ Integer
Returns the logging severity threshold.
127 |
# File 'lib/kitchen/logger.rb', line 127 delegate_to_first_logger :level |
#level=(level) ⇒ Object
Sets the logging severity threshold.
134 |
# File 'lib/kitchen/logger.rb', line 134 delegate_to_all_loggers :level= |
#metadata ⇒ Hash
Returns metadata added to structured log events.
314 315 316 317 318 |
# File 'lib/kitchen/logger.rb', line 314 def .inject(@base_metadata.dup) do |result, values| result.merge(values) end end |
#progname ⇒ String
Returns program name to include in log messages.
139 |
# File 'lib/kitchen/logger.rb', line 139 delegate_to_first_logger :progname |
#progname=(progname) ⇒ Object
Sets the program name to include in log messages.
146 |
# File 'lib/kitchen/logger.rb', line 146 delegate_to_all_loggers :progname= |
#unknown(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of unknown.
305 |
# File 'lib/kitchen/logger.rb', line 305 delegate_to_all_loggers :unknown |
#warn(message_or_progname = nil) { ... } ⇒ nil, true
Log a message with severity of warn.
265 |
# File 'lib/kitchen/logger.rb', line 265 delegate_to_all_loggers :warn |
#warn? ⇒ true, false
Returns whether or not the current severity level allows for the printing of warn messages.
271 |
# File 'lib/kitchen/logger.rb', line 271 delegate_to_first_logger :warn? |
#with_metadata(values) ⇒ Object
Temporarily adds metadata to structured log events.
323 324 325 326 327 328 |
# File 'lib/kitchen/logger.rb', line 323 def (values) .push(values.compact) yield ensure .pop end |