Class: Sawmill::RecordProcessor::Format

Inherits:
Base
  • Object
show all
Defined in:
lib/sawmill/record_processor/format.rb

Overview

This processor formats log records and writes them to a destination.

Instance Method Summary collapse

Methods inherited from Base

add_dsl_method, inherited

Constructor Details

#initialize(destination_, opts_ = {}) ⇒ Format

Create a formatter.

The destination can be a ruby IO object, a Sawmill::Rotater, or any object that responds to the “write” and “close” methods as defined by the ruby IO class.

Recognized options include:

:include_id

Include the record ID in every log entry. Default is false.

:fractional_second_digits

Number of digits of fractional seconds to display in timestamps. Default is 2. Accepted values are 0 to 6.

:level_width

Column width of the level field.

:entry_length_limit

Limit to the entry length. Entries are truncated to this length when written. If not specified, entries are not truncated.



66
67
68
69
70
71
72
# File 'lib/sawmill/record_processor/format.rb', line 66

def initialize(destination_, opts_={})
  if (entry_length_limit_ = opts_.delete(:entry_length_limit))
    opts_ = opts_.merge(:length_limit => entry_length_limit_)
  end
  @formatter = EntryProcessor::Format.new(destination_, opts_)
  @classifier = EntryClassifier.new(@formatter)
end

Instance Method Details

#extra_entry(entry_) ⇒ Object



80
81
82
83
# File 'lib/sawmill/record_processor/format.rb', line 80

def extra_entry(entry_)
  @classifier.entry(entry_)
  true
end

#finishObject



85
86
87
# File 'lib/sawmill/record_processor/format.rb', line 85

def finish
  @formatter.finish
end

#record(record_) ⇒ Object



75
76
77
78
# File 'lib/sawmill/record_processor/format.rb', line 75

def record(record_)
  record_.each_entry{ |entry_| @classifier.entry(entry_) }
  true
end