Class: LibSL::Logger

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

Constant Summary collapse

RESET_COLOR =

Colors

"\e[0m"
ERROR_COLOR =

Reset

"\e[1m\e[31m"
DEBUG_COLOR =

Red

"\e[1m\e[37m"
INFO_COLOR =

Grey

"\e[1m\e[33m"
UNDERLINE =

Yellow

"\e[4m"

Instance Method Summary collapse

Constructor Details

#initialize(output = nil, debug = false, colors = true) ⇒ Logger

Underline



27
28
29
30
31
# File 'lib/logging.rb', line 27

def initialize(output=nil, debug=false, colors=true)
	@output = output.is_a?(LogFile) ? output : LogFile.new(output)
	@debug = debug
	@colors = colors
end

Instance Method Details

#debug(message, *args) ⇒ Object



39
40
41
42
# File 'lib/logging.rb', line 39

def debug(message, *args)
	return unless @debug
	log(:debug, message, *args)
end

#error(message, *args) ⇒ Object



48
49
50
# File 'lib/logging.rb', line 48

def error(message, *args)
	log(:error, message, *args)
end

#info(message, *args) ⇒ Object



44
45
46
# File 'lib/logging.rb', line 44

def info(message, *args)
	log(:info, message, *args)
end

#log(level, message, *args) ⇒ Object



33
34
35
36
37
# File 'lib/logging.rb', line 33

def log(level, message, *args)
	color = self.class.const_get("#{level.to_s.upcase}_COLOR".to_sym)
	@output << "[" << apply_color(color + UNDERLINE, level.to_s.upcase + " " + Time.now.strftime("%F %T")) << "] " \
			<< sprintf(apply_color(color, message), *args) << "\n"
end