Class: AxeLogger

Inherits:
Logger
  • Object
show all
Includes:
Colors
Defined in:
lib/axe_logger.rb

Defined Under Namespace

Modules: Colors

Constant Summary collapse

COLOR_CONFIG =
{
  :debug => GREEN,
  :info =>  BLUE,
  :warn =>  PURPLE,
  :error => RED
}
STACK_LEVEL =
1
STACK_EXP =
/(?<file>.+):(?<line>\d+):.*`(?<func>.+)'/

Constants included from Colors

Colors::BLUE, Colors::GREEN, Colors::PURPLE, Colors::RED

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*opts) ⇒ AxeLogger

Returns a new instance of AxeLogger.



21
22
23
24
# File 'lib/axe_logger.rb', line 21

def initialize (*opts)
  @date_format = '%m/%d/%Y %H:%M:%S'
  super
end

Instance Attribute Details

#date_formatObject

Returns the value of attribute date_format.



20
21
22
# File 'lib/axe_logger.rb', line 20

def date_format
  @date_format
end

Instance Method Details

#format_message(severity, datetime, progname, msg) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/axe_logger.rb', line 26

def format_message severity, datetime, progname, msg
  m = STACK_EXP.match caller[STACK_LEVEL+1].split('/').last
  time = datetime.strftime date_format
  color = COLOR_CONFIG[severity.downcase.to_sym]

  string_with_color("#{time} #{m[:file]}:#{m[:line]} (#{m[:func]}): ", color) +
  "#{msg}\n"
end