Class: Temporalio::ScopedLogger

Inherits:
SimpleDelegator
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#disable_scoped_valuesObject

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_getterBoolean

Returns Whether the scoped value appending is disabled.

Returns:

  • (Boolean)

    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

See Also:

  • Logger.add


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, message = 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 message.nil?
    if block_given?
      message = yield
    else
      message = 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
  new_message = if message.is_a?(Exception)
                  message.exception("#{message.message} #{scoped_values}")
                else
                  LogMessage.new(message, scoped_values)
                end
  super(severity, new_message, progname)
end

#debug(progname = nil) ⇒ Object

See Also:

  • Logger.debug


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

See Also:

  • Logger.error


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

See Also:

  • Logger.fatal


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

See Also:

  • Logger.info


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

See Also:

  • Logger.unknown


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

See Also:

  • Logger.warn


56
57
58
# File 'lib/temporalio/scoped_logger.rb', line 56

def warn(progname = nil, &)
  add(Logger::WARN, nil, progname, &)
end