Class: Yell::Adapters::Io

Inherits:
Base
  • Object
show all
Defined in:
lib/yell/adapters/io.rb

Direct Known Subclasses

File, Stderr, Stdout

Constant Summary collapse

Colors =

The possible unix log colors

{
  'DEBUG'   => "\e[32;1m",  # green;bold
  # 'INFO'    => "\e[0m",     # white
  'WARN'    => "\e[33;1m",  # yello;bold
  'ERROR'   => "\e[31;1m",  # red;bold
  'FATAL'   => "\e[35;1m",  # magenta;bold
  'UNKNOWN' => "\e[36m",    # cyan
  'DEFAULT' => "\e[0m"      # NONE
}

Instance Attribute Summary collapse

Attributes inherited from Base

#level, #options

Instance Method Summary collapse

Methods inherited from Base

#write

Constructor Details

#initialize(options = {}, &block) ⇒ Io

Returns a new instance of Io.



22
23
24
25
26
27
28
# File 'lib/yell/adapters/io.rb', line 22

def initialize( options = {}, &block )
  colorize options.fetch(:colorize, false)

  self.format = options[:format]

  super( options, &block )
end

Instance Attribute Details

#formatObject

Accessor to the formatter



20
21
22
# File 'lib/yell/adapters/io.rb', line 20

def format
  @format
end

Instance Method Details

#closeObject

Close the io stream



39
40
41
42
43
# File 'lib/yell/adapters/io.rb', line 39

def close
  @stream.close if @stream.respond_to? :close

  @stream = nil
end

#colorize(color = true) ⇒ Object Also known as: colorize!

Enable colorizing the log output.



55
56
57
# File 'lib/yell/adapters/io.rb', line 55

def colorize( color = true )
  @colorize = color
end

#streamObject

The IO stream

Adapter classes should provide their own implementation of this method.



34
35
36
# File 'lib/yell/adapters/io.rb', line 34

def stream
  raise 'Not implemented'
end