Module: Pione::Log::MessageLog

Included in:
Pione, Agent::JobManager, Agent::TupleSpaceClient, RuleEngine::BasicHandler
Defined in:
lib/pione/log/message-log.rb

Overview

MessageLog is a set of utility methods for sending messages to user.

Message Mode collapse

@@debug_mode =

This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.

false
@@quiet_mode =

This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.

false

Constant Summary collapse

MESSAGE_QUEUE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Queue.new

Message Mode collapse

Message Senders collapse

Class Method Details

.debug_mode { ... } ⇒ void

This method returns an undefined value.

Evaluate the block in debug mode.

Yields:

  • [] target block



28
29
30
31
32
33
# File 'lib/pione/log/message-log.rb', line 28

def debug_mode
  orig = @@debug_mode
  @@debug_mode = true
  yield
  @@debug_mode = orig
end

.debug_mode=(mode) ⇒ void

This method returns an undefined value.

Set debug mode.

Parameters:

  • mode (bool)

    flag of debug mode



41
42
43
# File 'lib/pione/log/message-log.rb', line 41

def debug_mode=(mode)
  @@debug_mode = mode
end

.debug_mode?bool

Return true if the system is debug mode.

Returns:

  • (bool)


49
50
51
# File 'lib/pione/log/message-log.rb', line 49

def debug_mode?
  @@debug_mode
end

.message(type, head, color, msg, level = 0) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Print the message with the color.

Parameters:

  • type (String)

    message type("debug", "info", "show", ">>>", "<<<")

  • color (Symbol)

    type color(:red, :green, :magenta)

  • msg (String)

    message content



176
177
178
179
180
# 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

.quiet_mode { ... } ⇒ void

This method returns an undefined value.

Evaluate the block in quiet mode.

Yields:

  • [] target block



59
60
61
62
63
64
# File 'lib/pione/log/message-log.rb', line 59

def quiet_mode
  orig = @@quiet_mode
  @@quiet_mode = true
  yield
  @@quiet_mode = orig
end

.quiet_mode=(mode) ⇒ void

This method returns an undefined value.

Set quiet mode.

Parameters:

  • mode (bool)

    flag of quiet mode



72
73
74
# File 'lib/pione/log/message-log.rb', line 72

def quiet_mode=(mode)
  @@quiet_mode = mode
end

.quiet_mode?bool

Return true if the system is quiet mode.

Returns:

  • (bool)


80
81
82
# File 'lib/pione/log/message-log.rb', line 80

def quiet_mode?
  @@quiet_mode
end

Instance Method Details

#debug_message(msg, level = 0, head = "debug") ⇒ void

This method returns an undefined value.

Send the debug message.

Parameters:

  • msg (String)

    debug message

  • level (Integer) (defaults to: 0)

    indent level

  • type (String)

    message heading type



96
97
98
99
100
# 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

#debug_message_begin(msg) ⇒ void

This method returns an undefined value.

Send the debug message to notify that something begins.

Parameters:

  • msg (String)

    debug message



107
108
109
# File 'lib/pione/log/message-log.rb', line 107

def debug_message_begin(msg)
  debug_message(msg, 0, ">>>")
end

#debug_message_end(msg) ⇒ void

This method returns an undefined value.

Send the debug message to notify that something ends.

Parameters:

  • msg (String)

    debug message



116
117
118
# File 'lib/pione/log/message-log.rb', line 116

def debug_message_end(msg)
  debug_message(msg, 0, "<<<")
end

#show(msg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Use this for debugging only.

Show the message.

Parameters:

  • msg (String)

    the message



162
163
164
# File 'lib/pione/log/message-log.rb', line 162

def show(msg)
  message(:debug, "show", :red, msg)
end

#user_message(msg, level = 0, head = "info", color = :green) ⇒ void

This method returns an undefined value.

Send the user message.

Parameters:

  • msg (String)

    user message

  • level (Integer) (defaults to: 0)

    indent level

  • type (String)

    message heading type



129
130
131
132
133
# 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

#user_message_begin(msg, level = 0) ⇒ void

This method returns an undefined value.

Send the user message to notify that something begins.

Parameters:

  • msg (String)

    user message



140
141
142
# File 'lib/pione/log/message-log.rb', line 140

def user_message_begin(msg, level=0)
  user_message(msg, level, "-->")
end

#user_message_end(msg, level = 0) ⇒ void

This method returns an undefined value.

Send the debug message to notify that something ends.

Parameters:

  • msg (String)

    debug message



149
150
151
# File 'lib/pione/log/message-log.rb', line 149

def user_message_end(msg, level=0)
  user_message(msg, level, "<--")
end