Class: ADAL::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/adal/logger.rb

Overview

Extended version of Ruby’s base logger class to support VERBOSE logging. This is consistent with ADAL logging across platforms.

The format of a log message is described in the Ruby docs at ruby-doc.org/stdlib-2.2.2/libdoc/logger/rdoc/Logger.html as SeverityID, [DateTime #pid] SeverityLabel – ProgName: message. SeverityID is the first letter of the severity. In the case of ADAL::Logger that means one of I, W, E, F. The DateTime object uses the to_s method of DateTime from stdlib which is ISO-8601. The ProgName will be the correlation id if one is sent or absent otherwise.

Constant Summary collapse

SEVS =
%w(VERBOSE INFO WARN ERROR FATAL)
VERBOSE =
SEVS.index('VERBOSE')

Instance Method Summary collapse

Constructor Details

#initialize(logdev, correlation_id) ⇒ Logger

Constructs a new Logger.

Parameters:

  • String|IO

    logdev A filename (String) or IO object (STDOUT, STDERR).

  • String

    correlation_id The UUID of the request context.



47
48
49
50
# File 'lib/adal/logger.rb', line 47

def initialize(logdev, correlation_id)
  super(logdev)
  @correlation_id = correlation_id
end

Instance Method Details

#error(message = nil, &block) ⇒ Object

:nocov:



69
70
71
# File 'lib/adal/logger.rb', line 69

def error(message = nil, &block)
  add(ERROR, message, @correlation_id, &block)
end

#fatal(message = nil, &block) ⇒ Object



73
74
75
# File 'lib/adal/logger.rb', line 73

def fatal(message = nil, &block)
  add(FATAL, message, @correlation_id, &block)
end

#format_severity(severity) ⇒ Object



52
53
54
# File 'lib/adal/logger.rb', line 52

def format_severity(severity)
  SEVS[severity] || 'ANY'
end

#info(message = nil, &block) ⇒ Object



77
78
79
# File 'lib/adal/logger.rb', line 77

def info(message = nil, &block)
  add(INFO, message, @correlation_id, &block)
end

#verbose(message = nil, &block) ⇒ Object



81
82
83
# File 'lib/adal/logger.rb', line 81

def verbose(message = nil, &block)
  add(VERBOSE, message, @correlation_id, &block)
end

#warn(message = nil, &block) ⇒ Object



85
86
87
# File 'lib/adal/logger.rb', line 85

def warn(message = nil, &block)
  add(WARN, message, @correlation_id, &block)
end