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.



241
242
243
# File 'lib/wcc.rb', line 241

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

Instance Method Details

#blackObject



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

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

#blueObject



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

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

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



255
256
257
258
259
260
261
262
263
# File 'lib/wcc.rb', line 255

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



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

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

#greenObject



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

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

#magentaObject



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

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

#redObject



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

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

#rstObject



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

def rst;    "\e[0m" end

#whiteObject



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

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

#yellowObject



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

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