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 =
{ 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) ⇒ Object
- #add(severity, message = nil, progname = nil) ⇒ Object
- #banner(msg = nil) ⇒ Object
- #close ⇒ Object
- #debug(msg = nil, &block) ⇒ Object
- #debug? ⇒ Boolean
- #error(msg = nil, &block) ⇒ Object
- #error? ⇒ Boolean
- #fatal(msg = nil, &block) ⇒ Object
- #fatal? ⇒ Boolean
- #info(msg = nil, &block) ⇒ Object
- #info? ⇒ Boolean
-
#initialize(logdev, metadata_provider) ⇒ StructuredLogdevLogger
constructor
A new instance of StructuredLogdevLogger.
- #stream(severity, msg) ⇒ Object
- #unknown(msg = nil, &block) ⇒ Object
- #warn(msg = nil, &block) ⇒ Object
- #warn? ⇒ Boolean
Constructor Details
#initialize(logdev, metadata_provider) ⇒ StructuredLogdevLogger
Returns a new instance of StructuredLogdevLogger.
556 557 558 559 560 561 562 563 |
# File 'lib/kitchen/logger.rb', line 556 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.
554 555 556 |
# File 'lib/kitchen/logger.rb', line 554 def datetime_format @datetime_format end |
#level ⇒ Object
Returns the value of attribute level.
552 553 554 |
# File 'lib/kitchen/logger.rb', line 552 def level @level end |
#progname ⇒ Object
Returns the value of attribute progname.
553 554 555 |
# File 'lib/kitchen/logger.rb', line 553 def progname @progname end |
Instance Method Details
#<<(msg) ⇒ Object
577 578 579 |
# File 'lib/kitchen/logger.rb', line 577 def <<(msg) line_buffer << msg end |
#add(severity, message = nil, progname = nil) ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/kitchen/logger.rb', line 565 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) ⇒ Object
581 582 583 584 |
# File 'lib/kitchen/logger.rb', line 581 def (msg = nil) = block_given? ? yield : msg write_event(INFO, , "banner") unless INFO < level end |
#close ⇒ Object
635 636 637 638 639 640 641 642 643 |
# File 'lib/kitchen/logger.rb', line 635 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, &block) ⇒ Object
591 592 593 |
# File 'lib/kitchen/logger.rb', line 591 def debug(msg = nil, &block) add(DEBUG, msg, nil, &block) end |
#debug? ⇒ Boolean
615 616 617 |
# File 'lib/kitchen/logger.rb', line 615 def debug? level <= DEBUG end |
#error(msg = nil, &block) ⇒ Object
603 604 605 |
# File 'lib/kitchen/logger.rb', line 603 def error(msg = nil, &block) add(ERROR, msg, nil, &block) end |
#error? ⇒ Boolean
627 628 629 |
# File 'lib/kitchen/logger.rb', line 627 def error? level <= ERROR end |
#fatal(msg = nil, &block) ⇒ Object
607 608 609 |
# File 'lib/kitchen/logger.rb', line 607 def fatal(msg = nil, &block) add(FATAL, msg, nil, &block) end |
#fatal? ⇒ Boolean
631 632 633 |
# File 'lib/kitchen/logger.rb', line 631 def fatal? level <= FATAL end |
#info(msg = nil, &block) ⇒ Object
595 596 597 |
# File 'lib/kitchen/logger.rb', line 595 def info(msg = nil, &block) add(INFO, msg, nil, &block) end |
#info? ⇒ Boolean
619 620 621 |
# File 'lib/kitchen/logger.rb', line 619 def info? level <= INFO end |
#stream(severity, msg) ⇒ Object
586 587 588 589 |
# File 'lib/kitchen/logger.rb', line 586 def stream(severity, msg) severity = severity_const(severity) write_event(severity, msg, "stream") unless severity < level end |
#unknown(msg = nil, &block) ⇒ Object
611 612 613 |
# File 'lib/kitchen/logger.rb', line 611 def unknown(msg = nil, &block) add(UNKNOWN, msg, nil, &block) end |
#warn(msg = nil, &block) ⇒ Object
599 600 601 |
# File 'lib/kitchen/logger.rb', line 599 def warn(msg = nil, &block) add(WARN, msg, nil, &block) end |
#warn? ⇒ Boolean
623 624 625 |
# File 'lib/kitchen/logger.rb', line 623 def warn? level <= WARN end |