Skip to content
This repository
Browse code

Programatically define the log level methods and use the Logger const…

…ants instead (SyslogLogger didnt define them as I expected)
  • Loading branch information...
commit 18dbfcb36369ebb800a22325f689ff4cf27ef467 1 parent 533451a
David Heinemeier Hansson authored October 19, 2011
31  activesupport/lib/active_support/tagged_logging.rb
... ...
@@ -1,3 +1,5 @@
  1
+require 'logger'
  2
+
1 3
 module ActiveSupport
2 4
   # Wraps any standard Logger class to provide tagging capabilities. Examples:
3 5
   #
@@ -27,29 +29,12 @@ def add(severity, message = nil, progname = nil, &block)
27 29
       @logger.add(severity, "#{tags}#{message}", progname, &block)
28 30
     end
29 31
 
30  
-
31  
-    def fatal(progname = nil, &block)
32  
-      add(@logger.class::FATAL, progname, &block)
33  
-    end
34  
-
35  
-    def error(progname = nil, &block)
36  
-      add(@logger.class::ERROR, progname, &block)
37  
-    end
38  
-
39  
-    def warn(progname = nil, &block)
40  
-      add(@logger.class::WARN, progname, &block)
41  
-    end
42  
-
43  
-    def info(progname = nil, &block)
44  
-      add(@logger.class::INFO, progname, &block)
45  
-    end
46  
-
47  
-    def debug(progname = nil, &block)
48  
-      add(@logger.class::DEBUG, progname, &block)
49  
-    end
50  
-
51  
-    def unknown(progname = nil, &block)
52  
-      add(@logger.class::UNKNOWN, progname, &block)
  32
+    %w( fatal error warn info debug unkown ).each do |severity|
  33
+      eval <<-EOM, nil, __FILE__, __LINE__ + 1
  34
+        def #{severity}(progname = nil, &block)
  35
+          add(Logger::#{severity.upcase}, progname, &block)
  36
+        end
  37
+      EOM
53 38
     end
54 39
 
55 40
 

0 notes on commit 18dbfcb

Please sign in to comment.
Something went wrong with that request. Please try again.