Class Lumberjack::Device::Writer
In: lib/lumberjack/device/writer.rb
Parent: Device

This logging device writes log entries as strings to an IO stream. By default, messages will be buffered and written to the stream in a batch when the buffer is full or when flush is called.

Methods

before_flush   buffer_size=   close   flush   new   stream   stream=   write  

Constants

DEFAULT_FIRST_LINE_TEMPLATE = "[:time :severity :progname(:pid) #:unit_of_work_id] :message".freeze
DEFAULT_ADDITIONAL_LINES_TEMPLATE = "#{Lumberjack::LINE_SEPARATOR}> [#:unit_of_work_id] :message".freeze

Attributes

buffer_size  [R]  The size of the internal buffer. Defaults to 32K.

Public Class methods

Create a new device to write log entries to a stream. Entries are converted to strings using a Template. The template can be specified using the :template option. This can either be a Proc or a string that will compile into a Template object.

If the template is a Proc, it should accept an LogEntry as its only argument and output a string.

If the template is a template string, it will be used to create a Template. The :additional_lines and :time_format options will be passed through to the Template constuctor.

The default template is "[:time :severity :progname(:pid) #:unit_of_work_id] :message" with additional lines formatted as "\n [#:unit_of_work_id] :message". The unit of work id will only appear if it is present.

The size of the internal buffer in bytes can be set by providing :buffer_size (defaults to 32K).

Public Instance methods

Set the buffer size in bytes. The device will only be physically written to when the buffer size is exceeded.

Close the underlying stream.

Flush the underlying stream.

Write an entry to the stream. The entry will be converted into a string using the defined template.

Protected Instance methods

Callback method that will be executed before data is written to the stream. Subclasses can override this method if needed.

Get the underlying stream.

Set the underlying stream.

[Validate]