diff --git a/lib/log4r/formatter/patternformatter.rb b/lib/log4r/formatter/patternformatter.rb
index fe0dbf9..d32aa34 100644
--- a/lib/log4r/formatter/patternformatter.rb
+++ b/lib/log4r/formatter/patternformatter.rb
@@ -24,6 +24,7 @@ class PatternFormatter < BasicFormatter
# %p - process ID aka PID
# %M - formatted message
# %l - Level in string form
+ # %L - Level in string form colorized
# %x - Nested Diagnostic Context (NDC)
# %X - Mapped Diagnostic Context (MDC), syntax is "%X{key}"
# %% - Insert a %
@@ -39,6 +40,16 @@ class PatternFormatter < BasicFormatter
"p" => 'Process.pid.to_s',
"M" => 'format_object(event.data)',
"l" => 'LNAMES[event.level]',
+ "L" => %q|case LNAMES[event.level]
+ when "ERROR"
+ "\e[31m#{LNAMES[event.level][0..3]}\e[0m"
+ when "WARN"
+ "\e[33m#{LNAMES[event.level][0..3]}\e[0m"
+ when "INFO"
+ "\e[32m#{LNAMES[event.level][0..3]}\e[0m"
+ else
+ LNAMES[event.level][0..3]
+ end|,
"x" => 'Log4r::NDC.get()',
"X" => 'Log4r::MDC.get("DTR_REPLACE")',
"%" => '"%"'
@@ -54,7 +65,7 @@ class PatternFormatter < BasicFormatter
# * $6 is the stuff after the directive or "" if not applicable
# * $7 is the remainder
- DirectiveRegexp = /([^%]*)((%-?\d*(\.\d+)?)([cCdgtTmhpMlxX%]))?(\{.+?\})?(.*)/
+ DirectiveRegexp = /([^%]*)((%-?\d*(\.\d+)?)([cCdgtTmhpMlLxX%]))?(\{.+?\})?(.*)/
# default date format
ISO8601 = "%Y-%m-%d %H:%M:%S"
diff --git a/lib/log4r/rdoc/patternformatter b/lib/log4r/rdoc/patternformatter
index 635a253..259e739 100644
--- a/lib/log4r/rdoc/patternformatter
+++ b/lib/log4r/rdoc/patternformatter
@@ -61,6 +61,7 @@ terminology.
BasicFormatter. It will pretty-print Exceptions, print Strings
and inspect everything else. Slow.
[l] The name of the level. That's l as in Lambda. Fast.
+[L] The name of the level colorized and truncated to first 4 characters. Fast.
[%] %% just prints a %. Any formatting is probably ignored.
Fast.