Permalink
Browse files

Add :timestamp option. Also document :prepend.

  • Loading branch information...
1 parent b2769fa commit ae73b7f12190e8eef2814e7c9eb002c1fd9e110a @ffmike ffmike committed Sep 19, 2011
Showing with 23 additions and 15 deletions.
  1. +3 −1 README.rdoc
  2. +1 −1 lib/capistrano_colors.rb
  3. +7 −2 lib/capistrano_colors/configuration.rb
  4. +12 −11 lib/capistrano_colors/logger.rb
View
@@ -34,7 +34,9 @@ When capistrano_colors is included in your deploy.rb capistrano output gets nice
* :color - The color we want on the matching rows.
* :prio - What prio should this rule have (higher = more prio)
* :attribute - Special effect (:underline, :reverse, :blink)
- * :level - Specify if this matcher should be bound to some of capistranos log levels (info,debug,...)
+ * :level - Specify if this matcher should be bound to some of capistranos log levels (info,debug,...)
+ * :prepend - Text to be prepended to the output
+ * :timestamp - Show current time with the output
=== match
:match is a simple regular expression for the row that should be matched.
@@ -5,7 +5,7 @@
require 'capistrano_colors/logger'
# DEBUG
-Capistrano::Logger.add_color_matcher({ :match => /executing `.*/, :color => :green, :level => 2, :prio => -10, :prepend => "== Currently " })
+Capistrano::Logger.add_color_matcher({ :match => /executing `.*/, :color => :green, :level => 2, :prio => -10, :prepend => "== Currently ", :timestamp => true })
Capistrano::Logger.add_color_matcher({ :match => /.*/, :color => :yellow, :level => 2, :prio => -20 })
# INFO
@@ -12,8 +12,8 @@ class Configuration
# require 'capistrano_colors'
#
# capistrano_color_matchers = [
- # { :match => /command finished/, :color => :hide, :prio => 10 },
- # { :match => /executing command/, :color => :blue, :prio => 10, :attribute => :underscore },
+ # { :match => /command finished/, :color => :hide, :prio => 10, :prepend => "$$$" },
+ # { :match => /executing command/, :color => :blue, :prio => 10, :attribute => :underscore, :timestamp => true },
# { :match => /^transaction: commit$/, :color => :magenta, :prio => 10, :attribute => :blink },
# { :match => /git/, :color => :white, :prio => 20, :attribute => :reverse },
# ]
@@ -48,6 +48,11 @@ class Configuration
# * :reverse
# * :hidden
#
+ #
+ # == Text alterations
+ #
+ # :prepend gives static text to be prepended to the output
+ # :timestamp adds the current time before the output
#
def colorize(options)
@@ -1,7 +1,7 @@
module Capistrano
class Logger
- CAP_COLORS = {
+ CAP_COLORS = {
:none => "0",
:black => "30",
:red => "31",
@@ -11,7 +11,7 @@ class Logger
:magenta => "35",
:cyan => "36",
:white => "37"
- }
+ }
CAP_ATTRIBUTES = {
:bright => 1,
@@ -23,28 +23,29 @@ class Logger
}
@@color_matchers = []
-
+
alias_method :org_log, :log
def log(level, message, line_prefix=nil) #:nodoc:
-
+
color = :none
attribute = nil
-
+
# Sort matchers in reverse order so we can break if we found a match.
@@sorted_color_matchers ||= @@color_matchers.sort_by { |i| -i[:prio] }
-
+
@@sorted_color_matchers.each do |filter|
-
+
if (filter[:level] == level || filter[:level].nil?)
if message =~ filter[:match] || line_prefix =~ filter[:match]
color = filter[:color]
attribute = filter[:attribute]
message = filter[:prepend] + message unless filter[:prepend].nil?
+ message = Time.now.strftime('%T') + ' ' + message if filter[:timestamp]
break
end
end
-
+
end
if color != :hide
@@ -54,13 +55,13 @@ def log(level, message, line_prefix=nil) #:nodoc:
line_prefix = colorize(line_prefix.to_s, current_color, current_attribute, nil) unless line_prefix.nil?
org_log(level, colorize(message, current_color, current_attribute), line_prefix)
end
-
+
end
def self.add_color_matcher( options ) #:nodoc:
@@color_matchers.push( options )
- end
-
+ end
+
def colorize(message, color, attribute, nl = "\n")
attribute = "#{attribute};" if attribute
"\e[#{attribute}#{color}m" + message.strip + "\e[0m#{nl}"

0 comments on commit ae73b7f

Please sign in to comment.