Module: Libis::Workflow::Base::Logging

Included in:
WorkItem
Defined in:
lib/libis/workflow/base/logging.rb

Instance Method Summary collapse

Instance Method Details

#<=(message = {}) ⇒ Object



46
47
48
# File 'lib/libis/workflow/base/logging.rb', line 46

def <=(message = {})
  self.add_log(message)
end

#add_log(message = {}) ⇒ Object

Helper function for the WorkItems to add a log entry to the log_history.

The supplied message structure is expected to contain the following fields:

  • :severity : ::Logger::Severity value

  • :id : optional message id

  • :text : message text

  • :task : list of tasks names (task hierarchy) that submits the message

Parameters:

  • message (Hash) (defaults to: {})


40
41
42
43
44
# File 'lib/libis/workflow/base/logging.rb', line 40

def add_log(message = {})
  msg = message_struct(message)
  add_log_entry(msg)
  self.save!
end

#log_message(severity, msg, *args) ⇒ Object

Add a structured message to the log history. The message text can be submitted as an integer or text. If an integer is submitted, it will be used to look up the text in the MessageRegistry. The message text will be passed to the % operator with the args parameter. If that failes (e.g. because the format string is not correct) the args value is appended to the message.

Parameters:

  • severity (Symbol)
  • msg (Hash)

    should contain message text as :id or :text and the hierarchical name of the task as :task

  • args (Array)

    string format values



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/libis/workflow/base/logging.rb', line 14

def log_message(severity, msg, *args)
  # Prepare info from msg struct for use with string substitution
  message_id, message_text = if msg[:id]
                               [msg[:id], MessageRegistry.instance.get_message(msg[:id])]
                             elsif msg[:text]
                               [0, msg[:text]]
                             else
                               [0, '']
                             end
  task = msg[:task] || ''
  message_text = (message_text % args rescue "#{message_text} - #{args}")

  run_id = self.get_run.id rescue nil

  self.add_log severity: severity, id: message_id.to_i, text: message_text, task: task, run_id: run_id
end