Class: Mqlight::Logging::MqlightLogger

Inherits:
Logger
  • Object
show all
Includes:
Severity
Defined in:
lib/mqlight/logging.rb

Overview

The logger used by all internal MQ Light classes

Defined Under Namespace

Modules: Severity

Constant Summary collapse

NO_CLIENT_ID =

The identifier used when a log entry is not associated with a particular client.

'*'

Constants included from Severity

Severity::ALL, Severity::DATA, Severity::DATA_OFTEN, Severity::DEBUG, Severity::DETAIL, Severity::EMIT, Severity::ENTRY, Severity::ENTRY_EXIT, Severity::ENTRY_OFTEN, Severity::ERROR, Severity::EXIT, Severity::EXIT_OFTEN, Severity::FFDC, Severity::HEADER, Severity::OFTEN, Severity::PARMS, Severity::PROTON, Severity::PROTON_DATA, Severity::PROTON_ENTRY, Severity::PROTON_EXIT, Severity::RAW, Severity::UNKNOWN

Instance Method Summary collapse

Constructor Details

#initialize(logdev, shift_age = 0, shift_size = 1_048_576) ⇒ MqlightLogger

Returns a new instance of MqlightLogger.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/mqlight/logging.rb', line 84

def initialize(logdev, shift_age = 0, shift_size = 1_048_576)
  super(logdev, shift_age, shift_size)
  @ffdc_sequence = 0
  if ENV['MQLIGHT_RUBY_LOG'] 
    begin
    @level_name = ENV['MQLIGHT_RUBY_LOG'].upcase
      self.level = Severity.const_get(@level_name)
      header
    rescue
      @level_name = 'FFDC'
      self.level = FFDC
    end
  else
    @level_name = 'FFDC'
    self.level = FFDC
  end
end

Instance Method Details

#exit(progname = NO_CLIENT_ID, rc = nil, &block) ⇒ Object

Log exit from a method.

Parameters:

  • progname (String) (defaults to: NO_CLIENT_ID)

    The id of the client logging the exception

  • rc (defaults to: nil)

    The yielded value of the method

  • block

    The name of the method that is being exited



113
114
115
116
117
118
119
120
121
# File 'lib/mqlight/logging.rb', line 113

def exit(progname = NO_CLIENT_ID, rc = nil, &block)
  progname = NO_CLIENT_ID unless progname.is_a? String
  begin
    msg = yield.to_s + ' ' + rc.class.to_s + '->' + rc.to_s unless rc.nil?
  rescue => e
    msg = nil
  end
  add(EXIT, msg, (format_sev('exit') + progname), &block)
end

#ffdc(_fnc = 'User-requested FFDC by function', probe_id = 255, client, data, exception) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/mqlight/logging.rb', line 135

def ffdc(_fnc = 'User-requested FFDC by function',
         probe_id = 255, client, data, exception)
  entry(@id) { self.class.to_s + '#' + __method__.to_s }
  parms = Hash[method(__method__).parameters.map do |parm|
    [parm[1], eval(parm[1].to_s)]
  end]
  parms(@id, parms) { self.class.to_s + '#' + __method__.to_s }

  @ffdc_sequence += 1

  add(FFDC, ('-' * 80), format_sev('ffdc'))
  add(FFDC, 'First Failure Data Capture', format_sev('ffdc'))
  header
  if exception && (exception.is_a? Exception)
    add(FFDC, 'Error', format_sev('ffdc'))
    add(FFDC, exception.inspect, format_sev('ffdc'))
    add(FFDC, exception.backtrace, format_sev('ffdc'))
  end
  add(FFDC, '', format_sev('ffdc'))
  add(FFDC, 'Function Stack', format_sev('ffdc'))
  caller.each do |key, value|
    add(FFDC, key.to_s + '=>' + value.to_s, format_sev('ffdc'))
  end
  add(FFDC, '', format_sev('ffdc'))
  if client
    add(FFDC, 'Client', format_sev('ffdc'))
    add(FFDC, client.to_s, format_sev('ffdc'))
    add(FFDC, '', format_sev('ffdc'))
  end
  if data
    add(FFDC, 'Data', format_sev('ffdc'))
    add(FFDC, data.to_s, format_sev('ffdc'))
    add(FFDC, '', format_sev('ffdc'))
  end
  if (@ffdc_sequence == 1) || (probe_id == 255)
    add(FFDC, 'Environment Variables', format_sev('ffdc'))
    ENV.to_hash.each do |key, value|
      add(FFDC, key.to_s + '=>' + value.to_s, format_sev('ffdc'))
    end
    add(FFDC, ('-' * 80), format_sev('ffdc'))
  end

  exit(@id) { self.class.to_s + '#' + __method__.to_s }
rescue => e
  throw(nil, e) { self.class.to_s + '#' + __method__.to_s }
  raise e
end

#format_message(_severity, datetime, progname, msg) ⇒ Object



102
103
104
105
106
# File 'lib/mqlight/logging.rb', line 102

def format_message(_severity, datetime, progname, msg)
  "#{datetime.strftime('%H:%M:%S.%L')} [" +
    format('%-14s', "#{Process.pid}:#{Thread.current.object_id}") +
    "] #{progname} #{msg}\n"
end

#throw(id = NO_CLIENT_ID, err = nil, &_block) ⇒ Object

Log an exception being thrown.

Parameters:

  • id (String) (defaults to: NO_CLIENT_ID)

    The id of the client logging the exception

  • err (String) (defaults to: nil)

    The exception being thrown

  • _block (Method)

    The name of the method that is being exited



128
129
130
131
132
133
# File 'lib/mqlight/logging.rb', line 128

def throw(id = NO_CLIENT_ID, err = nil, &_block)
  id = NO_CLIENT_ID unless id.is_a? String
  add(ERROR, '* Thrown exception: ' + err.class.to_s + \
    ': ' + err.to_s, (format_sev('exit') + id))
  add(EXIT, (yield.to_s + ' Exception thrown'), (format_sev('exit') + id))
end