3
# Impliments a syslog based logger using the standard ruby syslog class
4
class Console_logger<Base
8
config = Config.instance
9
set_level(config.loglevel.to_sym) if config.configured
12
def set_logging_level(level)
13
# nothing to do here, we ignore high levels when we log
24
def log(level, from, msg)
25
if @known_levels.index(level) >= @known_levels.index(@active_level)
26
time = Time.new.strftime("%Y/%m/%d %H:%M:%S")
27
lvltxt = colorize(level, level)
28
STDERR.puts("#{lvltxt} #{time}: #{from} #{msg}")
31
# if this fails we probably cant show the user output at all,
32
# STDERR it as last resort
33
STDERR.puts("#{level}: #{msg}")
36
# Set some colors for various logging levels, will honor the
37
# color configuration option and return nothing if its configured
40
colorize = Config.instance.color
42
colors = {:error => "[31m",
49
return colors[level] || ""
55
# Helper to return a string in specific color
56
def colorize(level, msg)
57
"#{self.color(level)}#{msg}#{self.color(:reset)}"