3 # Implements 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, normal_output=STDERR, last_resort_output=STDERR)
25 time = Time.new.strftime("%Y/%m/%d %H:%M:%S")
27 normal_output.puts("%s %s: %s %s" % [colorize(level, level), time, from, msg])
29 # if this fails we probably cant show the user output at all,
30 # STDERR it as last resort
31 last_resort_output.puts("#{level}: #{msg}")
34 # Set some colors for various logging levels, will honor the
35 # color configuration option and return nothing if its configured
38 colorize = Config.instance.color
40 colors = {:error => Util.color(:red),
41 :fatal => Util.color(:red),
42 :warn => Util.color(:yellow),
43 :info => Util.color(:green),
44 :reset => Util.color(:reset)}
47 return colors[level] || ""
53 # Helper to return a string in specific color
54 def colorize(level, msg)
55 "%s%s%s" % [ color(level), msg, color(:reset) ]