Class: LoggingClass

Inherits:
Object
  • Object
show all
Defined in:
lib/miq_utilities/logging.rb

Overview

Wrapper class for logging

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ LoggingClass

initialize class



22
23
24
25
# File 'lib/miq_utilities/logging.rb', line 22

def initialize(name)
  @initializer = name
  @notification = NotificationClass.new
end

Instance Method Details

#log(level:, message:, logtoscreenonly: false, notify: false, email_to: nil, email_from: nil, signature: nil, webhookurl: nil, subjecttype: nil, update_message: false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/miq_utilities/logging.rb', line 27

def log(level:, message:, logtoscreenonly: false, notify: false, email_to: nil, email_from: nil, signature: nil, webhookurl: nil, subjecttype: nil, update_message: false)
  levelvalid = %w[info warn error debug].any? { |msglevel| level.upcase.include? msglevel.to_s.upcase }

  if $evm.nil? || logtoscreenonly
    puts "#{level}: #{@initializer} - #{message}"
  elsif levelvalid
    $evm.log(level, "#{@initializer} - #{message}")
    @task.message = message if @task && (level.casecmp('ERROR').zero? || update_message)
  else
    $evm.log('info', "#{@initializer} - #{message}")
  end

  # Notify - Only if flag (notify) is set to TRUE
  @notification.notify(event_level: level, event_message: message, email_to: email_to, email_from: email_from, signature: signature, webhookurl: webhookurl, subjecttype: subjecttype) if notify
rescue => err
  raise("Oopps! Something went wrong.\nDetails:<#{err}>")
end