Monitor
The Log class implements a filter for segmented execution traces. The trace messages are filtered based on their segment name and the nesting level of the segments. The class is a Singleton, so there is only one instance in the program.
Use this function to show a log message within the currently active segment.
# File lib/Log.rb, line 84 84: def Log.<<(message) 85: return if @@level == 0 86: 87: offset = 0 88: unless @@segments.empty? 89: showMessage = false 90: @@stack.each do |segment| 91: # If a segment list is used to filter the output, we look for the 92: # first listed segments on the stack. This and all nested segments 93: # will be shown. 94: if @@segments.include?(segment) && 95: (offset = @@stack.length - @@stack.index(segment)) >= @@level 96: showMessage = true 97: break 98: end 99: end 100: return unless showMessage 101: end 102: if @@stack.length - offset < @@level 103: $stderr.puts ' ' * (@@stack.length - offset) + message 104: end 105: end
This function may only be called when Log#startProgressMeter has been called before. It updates the progress indicator to the next symbol to visualize ongoing activity.
# File lib/Log.rb, line 141 141: def Log.activity 142: return if @@silent 143: 144: indicator = %( - \\ | / ) 145: @@progress = (@@progress.to_i + 1) % indicator.length 146: $stdout.print("#{@@progressMeter} [#{indicator[@@progress]}]\r") 147: end
This function is used to open a new segment. segment is the name of the segment and message is a description of it.
# File lib/Log.rb, line 60 60: def Log.enter(segment, message) 61: return if @@level == 0 62: 63: @@stack << segment 64: Log.<< ">> [#{segment}] #{message}" 65: end
This function is used to close an open segment. To make this mechanism a bit more robust, it will search the stack of open segments for a segment with that name and will close all nested segments as well.
# File lib/Log.rb, line 70 70: def Log.exit(segment, message = nil) 71: return if @@level == 0 72: 73: Log.<< "<< [#{segment}] #{message}" if message 74: if @@stack.include?(segment) 75: loop do 76: m = @@stack.pop 77: break if m == segment 78: end 79: end 80: end
Set the maximum nesting level that should be shown. Segments with a nesting level greater than l will be silently dropped.
# File lib/Log.rb, line 36 36: def Log.level=(l) 37: @@level = l 38: end
This function may only be called when Log#startProgressMeter has been called before. It updates the progress bar to the given percent completion value. The value should be between 0.0 and 1.0.
# File lib/Log.rb, line 152 152: def Log.progress(percent) 153: return if @@silent 154: 155: percent = 0.0 if percent < 0.0 156: percent = 1.0 if percent > 1.0 157: @@progress = percent 158: 159: length = 16 160: full = (length * percent).to_i 161: bar = '=' * full + ' ' * (length - full) 162: label = (percent * 100.0).to_i.to_s + '%' 163: bar[length / 2 - label.length / 2, label.length] = label 164: $stdout.print("#{@@progressMeter} [#{bar}]\r") 165: end
The trace output can be limited to a list of segments. Messages not in these segments will be ignored. Messages from segments that are nested into the shown segments will be shown for the next @@level nested segments.
# File lib/Log.rb, line 44 44: def Log.segments=(s) 45: @@segments = [] 46: end
Return the @@silent value.
# File lib/Log.rb, line 54 54: def Log.silent 55: @@silent 56: end
if s is true, progress information will not be shown.
# File lib/Log.rb, line 49 49: def Log.silent=(s) 50: @@silent = s 51: end
The progress meter can be a textual progress bar or some animated character sequence that informs the user about ongoing activities. Call this function to start the progress meter display or to change the info text. The the meter is active the text cursor is always returned to the start of the same line. Consequent output will overwrite the last meter text.
# File lib/Log.rb, line 120 120: def Log.startProgressMeter(text) 121: return if @@silent 122: 123: maxlen = 60 124: text = text.ljust(maxlen) 125: text = text[0..maxlen - 1] if text.length > maxlen 126: @@progressMeter = text 127: $stdout.print("#{@@progressMeter} ...\r") 128: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.