module Pione::Log::MessageLog
MessageLog
is a set of utility methods for sending messages to user.
Constants
- MESSAGE_QUEUE
@api private
Public Class Methods
Evaluate the block in debug mode.
@yield []
target block
@return [void]
# File lib/pione/log/message-log.rb, line 28 def debug_mode orig = @@debug_mode @@debug_mode = true yield @@debug_mode = orig end
Return true if the system is debug mode.
@return [bool]
# File lib/pione/log/message-log.rb, line 49 def debug_mode? @@debug_mode end
Print the message with the color.
@param type [String]
message type("debug", "info", "show", ">>>", "<<<")
@param color [Symbol]
type color(:red, :green, :magenta)
@param msg [String]
message content
@api private
# File lib/pione/log/message-log.rb, line 176 def message(type, head, color, msg, level=0) write(TupleSpace::MessageTuple.new(type: type, head: head, color: color, contents: msg, level: level)) rescue NoMethodError MESSAGE_QUEUE.push "%s%s %s" % [" "*level, ("%5s" % head).color(color), msg] end
Evaluate the block in quiet mode.
@yield []
target block
@return [void]
# File lib/pione/log/message-log.rb, line 59 def quiet_mode orig = @@quiet_mode @@quiet_mode = true yield @@quiet_mode = orig end
Return true if the system is quiet mode.
@return [bool]
# File lib/pione/log/message-log.rb, line 80 def quiet_mode? @@quiet_mode end
Public Instance Methods
Send the debug message.
@param msg [String]
debug message
@param level [Integer]
indent level
@param type [String]
message heading type
@return [void]
# File lib/pione/log/message-log.rb, line 96 def debug_message(msg, level=0, head="debug") if debug_mode? and not(quiet_mode?) message(:debug, head, :magenta, " "*level + msg) end end
Send the debug message to notify that something begins.
@param msg [String]
debug message
@return [void]
# File lib/pione/log/message-log.rb, line 107 def debug_message_begin(msg) debug_message(msg, 0, ">>>") end
Send the debug message to notify that something ends.
@param msg [String]
debug message
@return [void]
# File lib/pione/log/message-log.rb, line 116 def debug_message_end(msg) debug_message(msg, 0, "<<<") end
Set debug mode.
@param [bool] mode
flag of debug mode
@return [void]
# File lib/pione/log/message-log.rb, line 41 def debug_mode=(mode) @@debug_mode = mode end
Set quiet mode.
@param [bool] mode
flag of quiet mode
@return [void]
# File lib/pione/log/message-log.rb, line 72 def quiet_mode=(mode) @@quiet_mode = mode end
Show the message.
@param msg [String]
the message
@note
Use this for debugging only.
@api private
# File lib/pione/log/message-log.rb, line 162 def show(msg) message(:debug, "show", :red, msg) end
Send the user message.
@param msg [String]
user message
@param level [Integer]
indent level
@param type [String]
message heading type
@return [void]
# File lib/pione/log/message-log.rb, line 129 def user_message(msg, level=0, head="info", color=:green) if not(quiet_mode?) message(:info, head, color, msg, level) end end
Send the user message to notify that something begins.
@param msg [String]
user message
@return [void]
# File lib/pione/log/message-log.rb, line 140 def user_message_begin(msg, level=0) user_message(msg, level, "-->") end
Send the debug message to notify that something ends.
@param [String] msg
debug message
@return [void]
# File lib/pione/log/message-log.rb, line 149 def user_message_end(msg, level=0) user_message(msg, level, "<--") end
Private Instance Methods
Evaluate the block in debug mode.
@yield []
target block
@return [void]
# File lib/pione/log/message-log.rb, line 28 def debug_mode orig = @@debug_mode @@debug_mode = true yield @@debug_mode = orig end
Return true if the system is debug mode.
@return [bool]
# File lib/pione/log/message-log.rb, line 49 def debug_mode? @@debug_mode end
Print the message with the color.
@param type [String]
message type("debug", "info", "show", ">>>", "<<<")
@param color [Symbol]
type color(:red, :green, :magenta)
@param msg [String]
message content
@api private
# File lib/pione/log/message-log.rb, line 176 def message(type, head, color, msg, level=0) write(TupleSpace::MessageTuple.new(type: type, head: head, color: color, contents: msg, level: level)) rescue NoMethodError MESSAGE_QUEUE.push "%s%s %s" % [" "*level, ("%5s" % head).color(color), msg] end
Evaluate the block in quiet mode.
@yield []
target block
@return [void]
# File lib/pione/log/message-log.rb, line 59 def quiet_mode orig = @@quiet_mode @@quiet_mode = true yield @@quiet_mode = orig end
Return true if the system is quiet mode.
@return [bool]
# File lib/pione/log/message-log.rb, line 80 def quiet_mode? @@quiet_mode end