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

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#level, #write

Constructor Details

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

Returns a new instance of Io.



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

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

  super
end

Instance Method Details

#closeObject

Close the io stream



36
37
38
39
40
# File 'lib/yell/adapters/io.rb', line 36

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

  @stream = nil
end

#colorize(color = true) ⇒ Object

Enable colorizing the log output.



52
53
54
# File 'lib/yell/adapters/io.rb', line 52

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

#format(pattern, date_pattern = nil) ⇒ Object

Set the format for your message.



43
44
45
46
47
48
49
# File 'lib/yell/adapters/io.rb', line 43

def format( pattern, date_pattern = nil )
  @formatter = case pattern
    when Yell::Formatter then pattern
    when false then Yell::Formatter.new( "%m" )
    else Yell::Formatter.new( pattern, date_pattern )
  end
end

#streamObject

The IO stream

Adapter classes should provide their own implementation of this method.



31
32
33
# File 'lib/yell/adapters/io.rb', line 31

def stream
  raise 'Not implemented'
end