Class: Kitchen::Logger::StructuredLogdevLogger
- Inherits:
-
Object
- Object
- Kitchen::Logger::StructuredLogdevLogger
- Includes:
- Logger::Severity
- Defined in:
- lib/kitchen/logger.rb
Overview
Internal class that emits one JSON object per log event.
Constant Summary collapse
- SEVERITY_NAMES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps stdlib Logger severity constants to their lowercase string names as they appear in emitted JSON events.
{ DEBUG => "debug", INFO => "info", WARN => "warn", ERROR => "error", FATAL => "fatal", UNKNOWN => "unknown", }.freeze
Instance Attribute Summary collapse
-
#datetime_format ⇒ Object
Returns the value of attribute datetime_format.
-
#level ⇒ Object
Returns the value of attribute level.
-
#progname ⇒ Object
Returns the value of attribute progname.
Instance Method Summary collapse
-
#<<(msg) ⇒ void
private
Appends raw stream output, emitting a structured event per complete line.
-
#add(severity, message = nil, progname = nil) { ... } ⇒ true
private
Writes a log event if the given severity meets the current level.
-
#banner(msg = nil) { ... } ⇒ void
private
Writes a banner event at info severity.
-
#close ⇒ void
private
Closes the underlying log device if it is open and supports closing.
-
#debug(msg = nil) { ... } ⇒ true
private
Writes a log event at debug severity.
- #debug? ⇒ Boolean
-
#error(msg = nil) { ... } ⇒ true
private
Writes a log event at error severity.
- #error? ⇒ Boolean
-
#fatal(msg = nil) { ... } ⇒ true
private
Writes a log event at fatal severity.
- #fatal? ⇒ Boolean
-
#info(msg = nil) { ... } ⇒ true
private
Writes a log event at info severity.
- #info? ⇒ Boolean
-
#initialize(logdev, metadata_provider) ⇒ StructuredLogdevLogger
constructor
A new instance of StructuredLogdevLogger.
-
#stream(severity, msg) ⇒ void
private
Writes a stream event at the given severity.
-
#unknown(msg = nil) { ... } ⇒ true
private
Writes a log event at unknown severity.
-
#warn(msg = nil) { ... } ⇒ true
private
Writes a log event at warn severity.
- #warn? ⇒ Boolean
Constructor Details
#initialize(logdev, metadata_provider) ⇒ StructuredLogdevLogger
Returns a new instance of StructuredLogdevLogger.
613 614 615 616 617 618 619 620 |
# File 'lib/kitchen/logger.rb', line 613 def initialize(logdev, ) @logdev = logdev @metadata_provider = @level = INFO @progname = "Kitchen" @sequence = 0 @mutex = Mutex.new end |
Instance Attribute Details
#datetime_format ⇒ Object
Returns the value of attribute datetime_format.
611 612 613 |
# File 'lib/kitchen/logger.rb', line 611 def datetime_format @datetime_format end |
#level ⇒ Object
Returns the value of attribute level.
609 610 611 |
# File 'lib/kitchen/logger.rb', line 609 def level @level end |
#progname ⇒ Object
Returns the value of attribute progname.
610 611 612 |
# File 'lib/kitchen/logger.rb', line 610 def progname @progname end |
Instance Method Details
#<<(msg) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Appends raw stream output, emitting a structured event per complete line.
651 652 653 |
# File 'lib/kitchen/logger.rb', line 651 def <<(msg) line_buffer << msg end |
#add(severity, message = nil, progname = nil) { ... } ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes a log event if the given severity meets the current level.
633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/kitchen/logger.rb', line 633 def add(severity, = nil, progname = nil) severity ||= UNKNOWN return true if severity < level = if .nil? block_given? ? yield : progname else end write_event(severity, , "log") end |
#banner(msg = nil) { ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Writes a banner event at info severity.
662 663 664 665 |
# File 'lib/kitchen/logger.rb', line 662 def (msg = nil) = block_given? ? yield : msg write_event(INFO, , "banner") unless INFO < level end |
#close ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Closes the underlying log device if it is open and supports closing.
769 770 771 772 773 774 775 776 777 |
# File 'lib/kitchen/logger.rb', line 769 def close return unless @logdev.respond_to?(:close) if @logdev.respond_to?(:closed?) @logdev.close unless @logdev.closed? else @logdev.close end end |
#debug(msg = nil) { ... } ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes a log event at debug severity.
686 687 688 |
# File 'lib/kitchen/logger.rb', line 686 def debug(msg = nil, &block) add(DEBUG, msg, nil, &block) end |
#debug? ⇒ Boolean
745 746 747 |
# File 'lib/kitchen/logger.rb', line 745 def debug? level <= DEBUG end |
#error(msg = nil) { ... } ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes a log event at error severity.
719 720 721 |
# File 'lib/kitchen/logger.rb', line 719 def error(msg = nil, &block) add(ERROR, msg, nil, &block) end |
#error? ⇒ Boolean
757 758 759 |
# File 'lib/kitchen/logger.rb', line 757 def error? level <= ERROR end |
#fatal(msg = nil) { ... } ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes a log event at fatal severity.
730 731 732 |
# File 'lib/kitchen/logger.rb', line 730 def fatal(msg = nil, &block) add(FATAL, msg, nil, &block) end |
#fatal? ⇒ Boolean
761 762 763 |
# File 'lib/kitchen/logger.rb', line 761 def fatal? level <= FATAL end |
#info(msg = nil) { ... } ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes a log event at info severity.
697 698 699 |
# File 'lib/kitchen/logger.rb', line 697 def info(msg = nil, &block) add(INFO, msg, nil, &block) end |
#info? ⇒ Boolean
749 750 751 |
# File 'lib/kitchen/logger.rb', line 749 def info? level <= INFO end |
#stream(severity, msg) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Writes a stream event at the given severity.
674 675 676 677 |
# File 'lib/kitchen/logger.rb', line 674 def stream(severity, msg) severity = severity_const(severity) write_event(severity, msg, "stream") unless severity < level end |
#unknown(msg = nil) { ... } ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes a log event at unknown severity.
741 742 743 |
# File 'lib/kitchen/logger.rb', line 741 def unknown(msg = nil, &block) add(UNKNOWN, msg, nil, &block) end |
#warn(msg = nil) { ... } ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Writes a log event at warn severity.
708 709 710 |
# File 'lib/kitchen/logger.rb', line 708 def warn(msg = nil, &block) add(WARN, msg, nil, &block) end |
#warn? ⇒ Boolean
753 754 755 |
# File 'lib/kitchen/logger.rb', line 753 def warn? level <= WARN end |