Class: GreenLog::SimpleWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/green_log/simple_writer.rb

Overview

A simple log formatter, aimed at humans.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dest) ⇒ SimpleWriter

Returns a new instance of SimpleWriter.



11
12
13
# File 'lib/green_log/simple_writer.rb', line 11

def initialize(dest)
  @dest = dest
end

Instance Attribute Details

#destObject (readonly)

Returns the value of attribute dest.



15
16
17
# File 'lib/green_log/simple_writer.rb', line 15

def dest
  @dest
end

Instance Method Details

#<<(entry) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/green_log/simple_writer.rb', line 17

def <<(entry)
  raise ArgumentError, "GreenLog::Entry expected" unless entry.is_a?(GreenLog::Entry)

  output = [
    format_part(entry, :severity),
    format_part(entry, :context),
    "--",
    format_part(entry, :message),
    format_part(entry, :data),
  ].compact.join(" ") + "\n"

  output << format_exception(entry.exception)

  dest << output
end