public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
Feature: Log Coloring for console output [#26 state:resolved]
markbates (author)
Thu Jul 31 11:10:25 -0700 2008
commit  006aadb593b186cb01890d240cb7136e8e43c2f5
tree    5df436e9d322ed95430d50a5216e2194b5e77908
parent  e815e3f8762974691c8c27dd4265fec3d4c9999c
...
26
27
28
 
29
30
31
...
26
27
28
29
30
31
32
0
@@ -26,6 +26,7 @@
0
 * [#34] Mack::l10n now raises exception with a fully qualified name.
0
 * [#33] mack-active_record now requires ActiveRecord 2.0.2 explicitly, not >=2.0.2
0
 * [#31] Added support for ruby-debug.
0
+* [#26] Log Coloring for console output.
0
 * [#24] Added mack-notifier support.
0
 * [#18] Added Page caching. All that's needed for using page caching is to require the mack-caching gem, turn on
0
   page caching in your config files with: 
...
15
16
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
19
20
...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
0
@@ -15,6 +15,31 @@ module Mack
0
 end
0
 
0
 unless Mack.logger
0
+
0
+  module Log4r # :nodoc:
0
+    class IOOutputter # :nodoc:
0
+
0
+      # let's not do this more than once. :)
0
+      unless Log4r::IOOutputter.private_instance_methods.include?("old_write")
0
+
0
+        alias_method :old_write, :write
0
+
0
+        def write(data)
0
+          case data
0
+          when /^(DEBUG:|INFO:|WARN:|ERROR:|FATAL:)\s\[.*\]\s(SELECT|INSERT|UPDATE|DELETE|CREATE|DROP)/
0
+            old_write(Color.yellow(data))
0
+          when /^(ERROR:|FATAL:)/
0
+            old_write(Color.red(data))
0
+          else
0
+            old_write(data)
0
+          end
0
+        end
0
+
0
+      end
0
+
0
+    end # IOOutputter
0
+  end # Log4r
0
+  
0
   log_directory = app_config.log_root || File.join(Mack.root, "log")
0
   FileUtils.mkdir_p(log_directory)
0
 
...
20
21
22
23
 
24
25
26
...
20
21
22
 
23
24
25
26
0
@@ -20,7 +20,7 @@ module Mack
0
           msg = "\n\t[#{request.request_method.upcase}] '#{request.path_info}'\n"
0
           msg << "\tSession ID: #{request.session.id}\n" if app_config.mack.use_sessions
0
           msg << "\tParameters: #{request.all_params}\n"
0
-          msg << "\tCompleted in #{@total_time} (#{@requests_per_second} reqs/sec) | #{response.status} [#{request.full_host}]"
0
+          msg << Color.green("\tCompleted in #{@total_time} (#{@requests_per_second} reqs/sec) | #{response.status} [#{request.full_host}]")
0
         else
0
           msg = "[#{request.request_method.upcase}] '#{request.path_info}' (#{total_time})"
0
         end
...
19
20
21
 
22
23
24
...
19
20
21
22
23
24
25
0
@@ -19,6 +19,7 @@ require 'genosaurus'
0
 require 'net/http'
0
 require 'pp'
0
 require 'test/unit'
0
+require 'redgreen'
0
 
0
 fl = File.join(File.dirname(__FILE__), "mack")
0
 
...
61
62
63
 
64
65
66
...
61
62
63
64
65
66
67
0
@@ -61,6 +61,7 @@ namespace :gem do
0
         s.add_dependency("rcov", "0.8.1.2.0")
0
         s.add_dependency("rspec", "1.1.4")
0
         s.add_dependency("ruby-debug", "0.10.0")
0
+        s.add_dependency("redgreen", "1.2.2")
0
       
0
         s.rubyforge_project = gh.project
0
         

Comments