Class: Temporalio::ScopedLogger
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Temporalio::ScopedLogger
- Defined in:
- lib/temporalio/scoped_logger.rb
Overview
Implementation via delegator to Logger that puts scoped values on the log message and appends them to the log message.
Defined Under Namespace
Classes: LogMessage
Instance Attribute Summary collapse
-
#disable_scoped_values ⇒ Object
Returns the value of attribute disable_scoped_values.
-
#scoped_values_getter ⇒ Boolean
Whether the scoped value appending is disabled.
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil) ⇒ Object (also: #log)
- #debug(progname = nil) ⇒ Object
- #error(progname = nil) ⇒ Object
- #fatal(progname = nil) ⇒ Object
- #info(progname = nil) ⇒ Object
- #unknown(progname = nil) ⇒ Object
- #warn(progname = nil) ⇒ Object
Instance Attribute Details
#disable_scoped_values ⇒ Object
Returns the value of attribute disable_scoped_values.
16 17 18 |
# File 'lib/temporalio/scoped_logger.rb', line 16 def disable_scoped_values @disable_scoped_values end |
#scoped_values_getter ⇒ Boolean
Returns Whether the scoped value appending is disabled.
12 13 14 |
# File 'lib/temporalio/scoped_logger.rb', line 12 def scoped_values_getter @scoped_values_getter end |
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object Also known as: log
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/temporalio/scoped_logger.rb', line 19 def add(severity, = nil, progname = nil) return true if (severity || Logger::Unknown) < level return super if scoped_values_getter.nil? || @disable_scoped_values scoped_values = scoped_values_getter.call return super if scoped_values.nil? if .nil? if block_given? = yield else = progname progname = nil end end # For exceptions we need to dup and append here, for everything else we # need to delegate to a log message = if .is_a?(Exception) .exception("#{.} #{scoped_values}") else LogMessage.new(, scoped_values) end super(severity, , progname) end |
#debug(progname = nil) ⇒ Object
46 47 48 |
# File 'lib/temporalio/scoped_logger.rb', line 46 def debug(progname = nil, &) add(Logger::DEBUG, nil, progname, &) end |
#error(progname = nil) ⇒ Object
61 62 63 |
# File 'lib/temporalio/scoped_logger.rb', line 61 def error(progname = nil, &) add(Logger::ERROR, nil, progname, &) end |
#fatal(progname = nil) ⇒ Object
66 67 68 |
# File 'lib/temporalio/scoped_logger.rb', line 66 def fatal(progname = nil, &) add(Logger::FATAL, nil, progname, &) end |
#info(progname = nil) ⇒ Object
51 52 53 |
# File 'lib/temporalio/scoped_logger.rb', line 51 def info(progname = nil, &) add(Logger::INFO, nil, progname, &) end |
#unknown(progname = nil) ⇒ Object
71 72 73 |
# File 'lib/temporalio/scoped_logger.rb', line 71 def unknown(progname = nil, &) add(Logger::UNKNOWN, nil, progname, &) end |
#warn(progname = nil) ⇒ Object
56 57 58 |
# File 'lib/temporalio/scoped_logger.rb', line 56 def warn(progname = nil, &) add(Logger::WARN, nil, progname, &) end |