Module: OFlow::HasLog

Included in:
Env, Flow, Task
Defined in:
lib/oflow/haslog.rb

Overview

Adds the ability to log by sending log requests to a log Task.

Instance Method Summary collapse

Instance Method Details

#debug(msg) ⇒ Object

Logs the message if logging level is at least debug.

Parameters:

  • msg (String)

    message to log



56
57
58
# File 'lib/oflow/haslog.rb', line 56

def debug(msg)
  log_msg(:debug, msg, full_name())
end

#debug?Boolean

Returns true if debug messages would be logged.

Returns:

  • (Boolean)

    true if debug messages would be logged.



50
51
52
# File 'lib/oflow/haslog.rb', line 50

def debug?()
  Env.log_level <= Logger::Severity::DEBUG
end

#error(msg) ⇒ Object

Logs the message if logging level is at least error.

Parameters:

  • msg (String)

    message to display or log



68
69
70
# File 'lib/oflow/haslog.rb', line 68

def error(msg)
  log_msg(:error, msg, full_name())
end

#error?Boolean

Returns true if errors would be logged.

Returns:

  • (Boolean)

    true if errors would be logged.



35
36
37
# File 'lib/oflow/haslog.rb', line 35

def error?()
  Env.log_level <= Logger::Severity::ERROR
end

#fatal(msg) ⇒ Object

Logs the message if logging level is at least fatal.

Parameters:

  • msg (String)

    message to display or log



80
81
82
# File 'lib/oflow/haslog.rb', line 80

def fatal(msg)
  log_msg(:fatal, msg, full_name())
end

#info(msg) ⇒ Object

Logs the message if logging level is at least info.

Parameters:

  • msg (String)

    message to display or log



62
63
64
# File 'lib/oflow/haslog.rb', line 62

def info(msg)
  log_msg(:info, msg, full_name())
end

#info?Boolean

Returns true if info messages would be logged.

Returns:

  • (Boolean)

    true if info messages would be logged.



45
46
47
# File 'lib/oflow/haslog.rb', line 45

def info?()
  Env.log_level <= Logger::Severity::INFO
end

#log=(t) ⇒ Object

Sets the log attribute.

Parameters:

  • t (Task)

    log Task



9
10
11
# File 'lib/oflow/haslog.rb', line 9

def log=(t)
  @log = t
end

#log_msg(level, msg, fn) ⇒ Object

Lower level logging method. Generally only used when one of the primary severity methods are called.

Parameters:

  • level (String)

    message severity or level

  • msg (String)

    message to log

  • fn (String)

    full name of Task or Flow calling the log function



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oflow/haslog.rb', line 18

def log_msg(level, msg, fn)
  # Abort early if the log severity/level would not log the message. This
  # also allows non-Loggers to be used in place of the Log Actor.
  return if Env.log_level > Actors::Log::SEVERITY_MAP[level]

  lt = log()
  # To prevent infinite looping, don't allow the logger to log to itself.
  return if self == lt

  unless lt.nil?
    lt.receive(level, Box.new([msg, fn]))
  else
    puts "[#{fn}] #{msg}"
  end
end

#warn(msg) ⇒ Object

Logs the message if logging level is at least warn.

Parameters:

  • msg (String)

    message to display or log



74
75
76
# File 'lib/oflow/haslog.rb', line 74

def warn(msg)
  log_msg(:warn, msg, full_name())
end

#warn?Boolean

Returns true if warn messages would be logged.

Returns:

  • (Boolean)

    true if warn messages would be logged.



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

def warn?()
  Env.log_level <= Logger::Severity::WARN
end