Class: VCAP::Logging::Sink::FileSink::MessageBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/vcap/logging/sink/file_sink.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buffer_size) ⇒ MessageBuffer

Returns a new instance of MessageBuffer.



12
13
14
15
16
# File 'lib/vcap/logging/sink/file_sink.rb', line 12

def initialize(buffer_size)
  @max_buffer_size = buffer_size
  @buffer = []
  @size   = 0
end

Instance Attribute Details

#max_buffer_sizeObject

Returns the value of attribute max_buffer_size.



10
11
12
# File 'lib/vcap/logging/sink/file_sink.rb', line 10

def max_buffer_size
  @max_buffer_size
end

#sizeObject (readonly)

Returns the value of attribute size.



9
10
11
# File 'lib/vcap/logging/sink/file_sink.rb', line 9

def size
  @size
end

Instance Method Details

#append(msg) ⇒ Object



18
19
20
21
# File 'lib/vcap/logging/sink/file_sink.rb', line 18

def append(msg)
  @buffer << msg
  @size += msg.length
end

#compactObject



23
24
25
26
27
28
29
# File 'lib/vcap/logging/sink/file_sink.rb', line 23

def compact
  return nil unless @size > 0
  ret = @buffer.join
  @buffer = []
  @size = 0
  ret
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/vcap/logging/sink/file_sink.rb', line 35

def empty?
  @size == 0
end

#full?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/vcap/logging/sink/file_sink.rb', line 31

def full?
  @size >= @max_buffer_size
end