Module: OFlow::HasLog
Overview
Adds the ability to log by sending log requests to a log Task.
Instance Method Summary collapse
-
#debug(msg) ⇒ Object
Logs the message if logging level is at least debug.
-
#error(msg) ⇒ Object
Logs the message if logging level is at least error.
-
#fatal(msg) ⇒ Object
Logs the message if logging level is at least fatal.
-
#info(msg) ⇒ Object
Logs the message if logging level is at least info.
-
#log ⇒ Task
Returns a log Task by looking for that Task in an attribute and then in the contained Tasks or Tasks in outer Flows.
-
#log=(t) ⇒ Object
Sets the log attribute.
-
#log_msg(level, msg, fn) ⇒ Object
Lower level logging method.
-
#warn(msg) ⇒ Object
Logs the message if logging level is at least warn.
Instance Method Details
#debug(msg) ⇒ Object
Logs the message if logging level is at least debug.
50 51 52 |
# File 'lib/oflow/haslog.rb', line 50 def debug(msg) log_msg(:debug, msg, full_name()) end |
#error(msg) ⇒ Object
Logs the message if logging level is at least error.
62 63 64 |
# File 'lib/oflow/haslog.rb', line 62 def error(msg) log_msg(:error, msg, full_name()) end |
#fatal(msg) ⇒ Object
Logs the message if logging level is at least fatal.
74 75 76 |
# File 'lib/oflow/haslog.rb', line 74 def fatal(msg) log_msg(:fatal, msg, full_name()) end |
#info(msg) ⇒ Object
Logs the message if logging level is at least info.
56 57 58 |
# File 'lib/oflow/haslog.rb', line 56 def info(msg) log_msg(:info, msg, full_name()) end |
#log ⇒ Task
Returns a log Task by looking for that Task in an attribute and then in the contained Tasks or Tasks in outer Flows.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/oflow/haslog.rb', line 10 def log() return @log if instance_variable_defined?(:@log) && !@log.nil? # Log task take precedence over log variable. if respond_to?(:find_task) lg = find_task(:log) return lg unless lg.nil? end return @flow.log if instance_variable_defined?(:@flow) && @flow.respond_to?(:log) nil end |
#log=(t) ⇒ Object
Sets the log attribute.
23 24 25 |
# File 'lib/oflow/haslog.rb', line 23 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/oflow/haslog.rb', line 32 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.
68 69 70 |
# File 'lib/oflow/haslog.rb', line 68 def warn(msg) log_msg(:warn, msg, full_name()) end |