Class: Couchbase::Utils::StdlibLoggerAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/utils/stdlib_logger_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger, verbose: false) ⇒ StdlibLoggerAdapter

Returns a new instance of StdlibLoggerAdapter.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
# File 'lib/couchbase/utils/stdlib_logger_adapter.rb', line 24

def initialize(logger, verbose: false)
  raise ArgumentError, "logger argument must be or derive from stdlib Logger class" unless logger.is_a?(::Logger)

  @logger = logger
  @verbose = verbose
end

Instance Method Details

#log(level, thread_id, seconds, nanoseconds, payload, filename, line, function) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/couchbase/utils/stdlib_logger_adapter.rb', line 31

def log(level, thread_id, seconds, nanoseconds, payload, filename, line, function)
  logdev = @logger.instance_variable_get(:@logdev)
  return unless logdev

  severity = map_spdlog_level(level)
  return unless severity

  progname = "cxxcbc##{thread_id}"
  payload += " at #{filename}:#{line} #{function}" if @verbose && filename
  logdev.write(
    @logger.send(:format_message, @logger.send(:format_severity, severity), ::Time.at(seconds, nanoseconds, :nanosecond), progname,
                 payload)
  )
end