Class: Giblish::AsciidoctorLogger
- Inherits:
-
Logger
- Object
- Logger
- Giblish::AsciidoctorLogger
- Defined in:
- lib/giblish/utils.rb
Overview
This logger is customized to receive log messages via the Asciidoctor API. It parses the messages and ‘source_location’ objects from the Asciidoctor API into messages using an opinionated format.
The output is written to both $stdout and an in-memory StringIO instance. The log level can be set separately for each of these output channels.
Defined Under Namespace
Classes: UserInfoFormatter
Instance Attribute Summary collapse
-
#in_mem_storage ⇒ Object
readonly
Returns the value of attribute in_mem_storage.
-
#max_severity ⇒ Object
readonly
Returns the value of attribute max_severity.
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
-
#initialize(user_logger, string_level = nil) ⇒ AsciidoctorLogger
constructor
The level is one of the standard ::Logger levels.
Constructor Details
#initialize(user_logger, string_level = nil) ⇒ AsciidoctorLogger
The level is one of the standard ::Logger levels
- stdout_level
-
the log level to use for gating the messages to stdout
- string_level
-
the log level to use for gating the messages to the in-memory string.
defaults to ‘stdout_level’ if not set.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/giblish/utils.rb', line 93 def initialize(user_logger, string_level = nil) # def initialize(stdout_level, string_level = nil) string_level = stdout_level if string_level.nil? @user_logger = user_logger @max_severity = UNKNOWN # create a new, internal logger that echos messages to an in-memory string @in_mem_storage = StringIO.new # @in_mem_logger = ::Logger.new(@in_mem_storage, formatter: UserInfoFormatter.new, level: string_level) super(@in_mem_storage, progname: "(asciidoctor)", formatter: UserInfoFormatter.new, level: string_level) end |
Instance Attribute Details
#in_mem_storage ⇒ Object (readonly)
Returns the value of attribute in_mem_storage.
44 45 46 |
# File 'lib/giblish/utils.rb', line 44 def in_mem_storage @in_mem_storage end |
#max_severity ⇒ Object (readonly)
Returns the value of attribute max_severity.
44 45 46 |
# File 'lib/giblish/utils.rb', line 44 def max_severity @max_severity end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/giblish/utils.rb', line 106 def add(severity, = nil, progname = nil, &block) # add message to adoc log super(severity, .dup, progname) # add message to user log (wierd interface... see Logger::add(...)) = yield if block ||= progname @user_logger&.add(severity, "(asciidoctor) #{UserInfoFormatter.()}") # update the maximum severity received by this logger @max_severity = severity if severity != UNKNOWN && severity > @max_severity end |