Class: OFlow::Actors::Log

Inherits:
OFlow::Actor show all
Defined in:
lib/oflow/actors/log.rb

Overview

An asynchronous logger build on top of the Actor class. It is able to log messages as well as forward calls to a Task.

Constant Summary collapse

SEVERITY_MAP =
{
  :fatal => Logger::Severity::FATAL,
  :error => Logger::Severity::ERROR,
  :warn => Logger::Severity::WARN,
  :info => Logger::Severity::INFO,
  :debug => Logger::Severity::DEBUG,
  :FATAL => Logger::Severity::FATAL,
  :ERROR => Logger::Severity::ERROR,
  :WARN => Logger::Severity::WARN,
  :INFO => Logger::Severity::INFO,
  :DEBUG => Logger::Severity::DEBUG,
}

Instance Attribute Summary

Attributes inherited from OFlow::Actor

#task

Instance Method Summary collapse

Methods inherited from OFlow::Actor

#busy?, #inputs, #options, #outputs, #set_option, #with_own_thread

Constructor Details

#initialize(task, options = {}) ⇒ Log

Returns a new instance of Log.



23
24
25
26
27
28
29
# File 'lib/oflow/actors/log.rb', line 23

def initialize(task, options={})
  @logger = nil
  @formatter = nil
  @name = nil
  super
  set_options(options)
end

Instance Method Details

#formatterLogger::Formatter

Returns the current formatter.

Returns:

  • (Logger::Formatter)

    current formatter



40
41
42
# File 'lib/oflow/actors/log.rb', line 40

def formatter()
  @formatter
end

#perform(op, box) ⇒ Object

Writes a log entry. op is the severity. The box contents is expected to be an Array with the first element as the full task name of the logging task and the second argument being the message to log



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/oflow/actors/log.rb', line 47

def perform(op, box)
  op = op.to_sym unless op.nil?
  a = box.contents
  case op
  when :severity
    self.severity = a
  when :formatter
    # TBD
  when :file, :filename
    # TBD
    # self.set_filename(filename, shift_age=7, shift_size=1048576)
  else
    level = SEVERITY_MAP.fetch(op, Logger::Severity::UNKNOWN)
    if a.is_a?(Array)
      log(level, a[0], a[1])
    else
      log(level, a.to_s, '')
    end
    # Forward to the next if there is a generic (nil) link.
    task.ship(nil, box) if task.find_link(nil)
  end
end

#severityFixnum Also known as: level

Returns the current severity level.

Returns:

  • (Fixnum)

    Logger severity level



33
34
35
# File 'lib/oflow/actors/log.rb', line 33

def severity()
  @logger.level
end