summaryrefslogtreecommitdiffstats
path: root/lib/puppet/log.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/log.rb')
-rw-r--r--lib/puppet/log.rb49
1 files changed, 29 insertions, 20 deletions
diff --git a/lib/puppet/log.rb b/lib/puppet/log.rb
index c76dd945c..8362e8d4d 100644
--- a/lib/puppet/log.rb
+++ b/lib/puppet/log.rb
@@ -6,13 +6,6 @@ module Puppet
# multiple destinations, one of which is a remote server.
class Log
include Puppet::Util
- PINK=""
- GREEN=""
- YELLOW=""
- SLATE=""
- ORANGE=""
- BLUE=""
- RESET=""
@levels = [:debug,:info,:notice,:warning,:err,:alert,:emerg,:crit]
@loglevel = 2
@@ -250,7 +243,17 @@ module Puppet
end
newdesttype :console do
- @@colors = {
+
+
+ PINK = {:console => "", :html => "FFA0A0"}
+ GREEN = {:console => "", :html => "00CD00"}
+ YELLOW = {:console => "", :html => "FFFF60"}
+ SLATE = {:console => "", :html => "80A0FF"}
+ ORANGE = {:console => "", :html => "FFA500"}
+ BLUE = {:console => "", :html => "40FFFF"}
+ RESET = {:console => "", :html => ""}
+
+ @@colormap = {
:debug => SLATE,
:info => GREEN,
:notice => PINK,
@@ -260,6 +263,22 @@ module Puppet
:emerg => RESET,
:crit => RESET
}
+
+ def colorize(level, str)
+ case Puppet[:color]
+ when false: str
+ when true, :ansi, "ansi": console_color(level, str)
+ when :html, "html": html_color(level, str)
+ end
+ end
+
+ def console_color(level, str)
+ @@colormap[level][:console] + str + RESET[:console]
+ end
+
+ def html_color(level, str)
+ %{<span style="color: %s">%s</span>} % [@@colormap[level][:html], str]
+ end
def initialize
# Flush output immediately.
@@ -267,20 +286,10 @@ module Puppet
end
def handle(msg)
- color = ""
- reset = ""
- if Puppet[:color]
- color = @@colors[msg.level]
- reset = RESET
- end
if msg.source == "Puppet"
- puts color + "%s: %s" % [
- msg.level, msg.to_s
- ] + reset
+ puts colorize(msg.level, "%s: %s" % [msg.level, msg.to_s])
else
- puts color + "%s: %s: %s" % [
- msg.level, msg.source, msg.to_s
- ] + reset
+ puts colorize(msg.level, "%s: %s: %s" % [msg.level, msg.source, msg.to_s])
end
end
end