Class: LogBuffer
- Inherits:
-
Object
- Object
- LogBuffer
- Defined in:
- lib/debugtrace/log_buffer.rb
Overview
Buffers logs.
Defined Under Namespace
Classes: LevelAndLog
Instance Method Summary collapse
-
#append(value, nest_level = 0, no_break = false) ⇒ Object
Appends a string representation of the value.
-
#append_buffer(separator, buff) ⇒ Object
Appends lines of another LogBuffer.
-
#down_nest ⇒ Object
Downs the data nest level.
-
#initialize(maximum_data_output_width) ⇒ LogBuffer
constructor
Initializes this object.
-
#length ⇒ Object
The length of the last line.
-
#line_feed ⇒ Object
Breaks the current line.
-
#lines ⇒ Object
A list of tuple of data indentation level && log string.
-
#multi_lines? ⇒ Boolean
true if multiple line, false otherwise.
-
#no_break_append(value) ⇒ Object
Appends a string representation of the value.
-
#up_nest ⇒ Object
Ups the data nest level.
Constructor Details
#initialize(maximum_data_output_width) ⇒ LogBuffer
Initializes this object.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/debugtrace/log_buffer.rb', line 28 def initialize(maximum_data_output_width) @maximum_data_output_width = Common.check_type('maximum_data_output_width', maximum_data_output_width, Integer) @nest_level = 0 @append_nest_level = 0 # tuples of data indentation level && log string @lines = [] # buffer for a line of logs @last_line = "" end |
Instance Method Details
#append(value, nest_level = 0, no_break = false) ⇒ Object
Appends a string representation of the value.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/debugtrace/log_buffer.rb', line 63 def append(value, nest_level = 0, no_break = false) Common.check_type('nest_level', nest_level, Integer) Common.check_type('no_break', no_break, TrueClass) if value != nil string = value.to_s if !no_break && length > 0 && length + string.length > @maximum_data_output_width line_feed() end @append_nest_level = nest_level @last_line += string end self end |
#append_buffer(separator, buff) ⇒ Object
Appends lines of another LogBuffer.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/debugtrace/log_buffer.rb', line 90 def append_buffer(separator, buff) Common.check_type('separator', separator, String) Common.check_type('buff', buff, LogBuffer) if separator != "" append(separator, 0, true) end index = 0 for line in buff.lines if index > 0 line_feed() end append(line.nest_level, line.log, index == 0 && separator != "") index += 1 end self end |
#down_nest ⇒ Object
Downs the data nest level.
53 54 55 |
# File 'lib/debugtrace/log_buffer.rb', line 53 def down_nest @nest_level -= 1 end |
#length ⇒ Object
The length of the last line.
108 109 110 |
# File 'lib/debugtrace/log_buffer.rb', line 108 def length @last_line.length end |
#line_feed ⇒ Object
Breaks the current line.
41 42 43 44 45 |
# File 'lib/debugtrace/log_buffer.rb', line 41 def line_feed @lines << LevelAndLog.new(@nest_level + @append_nest_level, @last_line.rstrip()) @append_nest_level = 0 @last_line = '' end |
#lines ⇒ Object
A list of tuple of data indentation level && log string.
118 119 120 121 122 123 124 |
# File 'lib/debugtrace/log_buffer.rb', line 118 def lines lines = @lines.dup if length > 0 lines << LevelAndLog.new(@nest_level, @last_line) end lines end |
#multi_lines? ⇒ Boolean
true if multiple line, false otherwise.
113 114 115 |
# File 'lib/debugtrace/log_buffer.rb', line 113 def multi_lines? @lines.length > 1 || @lines.length == 1 && length > 0 end |
#no_break_append(value) ⇒ Object
Appends a string representation of the value. Does not break even if the maximum width is exceeded.
81 82 83 |
# File 'lib/debugtrace/log_buffer.rb', line 81 def no_break_append(value) append(value, 0, true) end |
#up_nest ⇒ Object
Ups the data nest level.
48 49 50 |
# File 'lib/debugtrace/log_buffer.rb', line 48 def up_nest @nest_level += 1 end |