Class: WCC::LogFormatter

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

Instance Method Summary collapse

Constructor Details

#initialize(use_color = true) ⇒ LogFormatter

Returns a new instance of LogFormatter.



321
322
323
# File 'lib/wcc.rb', line 321

def initialize(use_color = true)
	@color = use_color
end

Instance Method Details

#blackObject



332
# File 'lib/wcc.rb', line 332

def black;  "\e[1;30m" end

#blueObject



328
# File 'lib/wcc.rb', line 328

def blue;   "\e[1;34m" end

#call(lvl, time, progname, msg) ⇒ Object



335
336
337
338
339
340
341
342
343
# File 'lib/wcc.rb', line 335

def call(lvl, time, progname, msg)
	text = "%s: %s" % [lvl, msg.to_s]
	if @color
		return [magenta, text, rst, "\n"].join if lvl == "FATAL"
		return [red, text, rst, "\n"].join if lvl == "ERROR"
		return [yellow, text, rst, "\n"].join if lvl == "WARN"
	end
	[text, "\n"].join
end

#cyanObject



326
# File 'lib/wcc.rb', line 326

def cyan;   "\e[1;36m" end

#greenObject



330
# File 'lib/wcc.rb', line 330

def green;  "\e[1;32m" end

#magentaObject



327
# File 'lib/wcc.rb', line 327

def magenta;"\e[1;35m" end

#redObject



331
# File 'lib/wcc.rb', line 331

def red;    "\e[1;31m" end

#rstObject



333
# File 'lib/wcc.rb', line 333

def rst;    "\e[0m" end

#whiteObject



325
# File 'lib/wcc.rb', line 325

def white;  "\e[1;37m" end

#yellowObject



329
# File 'lib/wcc.rb', line 329

def yellow; "\e[1;33m" end