Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add eh? methods for compatibility.

[git-p4: depot-paths = "//src/SyslogLogger/dev/": change = 3137]
  • Loading branch information...
commit 9fc413223ada1f2ff8726ab180ab7cd7f6d96445 1 parent 185070d
@drbrain drbrain authored
Showing with 57 additions and 4 deletions.
  1. +2 −1  History.txt
  2. +7 −3 lib/syslog_logger.rb
  3. +48 −0 test/test_syslog_logger.rb
View
3  History.txt
@@ -1,4 +1,5 @@
== 1.4.0 / 2007-04-21
-* Split from rails_analyzer_tools
+* Split from rails_analyzer_tools.
+* Added eh methods for compatibility with Logger.
View
10 lib/syslog_logger.rb
@@ -98,20 +98,24 @@ class SyslogLogger
end
##
- # Builds a logging method for level +meth+.
+ # Builds a methods for level +meth+.
- def self.log_method(meth)
+ def self.make_methods(meth)
eval <<-EOM, nil, __FILE__, __LINE__ + 1
def #{meth}(message = nil)
return true if #{LOGGER_LEVEL_MAP[meth]} < @level
SYSLOG.#{LOGGER_MAP[meth]} clean(message || yield)
return true
end
+
+ def #{meth}?
+ @level <= Logger::#{meth.to_s.upcase}
+ end
EOM
end
LOGGER_MAP.each_key do |level|
- log_method level
+ make_methods level
end
##
View
48 test/test_syslog_logger.rb
@@ -258,6 +258,14 @@ def test_unknown
assert_equal LEVEL_LABEL_MAP[Logger::UNKNOWN], msg.severity
end
+ def test_unknown_eh
+ @logger.level = Logger::UNKNOWN
+ assert_equal true, @logger.unknown?
+
+ @logger.level = Logger::UNKNOWN + 1
+ assert_equal false, @logger.unknown?
+ end
+
def test_fatal
msg = log :fatal, 'fatal level message'
assert_equal LEVEL_LABEL_MAP[Logger::FATAL], msg.severity
@@ -287,6 +295,14 @@ def test_fatal
assert_equal LEVEL_LABEL_MAP[Logger::FATAL], msg.severity
end
+ def test_fatal_eh
+ @logger.level = Logger::FATAL
+ assert_equal true, @logger.fatal?
+
+ @logger.level = Logger::UNKNOWN
+ assert_equal false, @logger.fatal?
+ end
+
def test_error
msg = log :error, 'error level message'
assert_equal LEVEL_LABEL_MAP[Logger::ERROR], msg.severity
@@ -316,6 +332,14 @@ def test_error
assert_equal LEVEL_LABEL_MAP[Logger::ERROR], msg.severity
end
+ def test_error_eh
+ @logger.level = Logger::ERROR
+ assert_equal true, @logger.error?
+
+ @logger.level = Logger::FATAL
+ assert_equal false, @logger.error?
+ end
+
def test_warn
msg = log :warn, 'warn level message'
assert_equal LEVEL_LABEL_MAP[Logger::WARN], msg.severity
@@ -345,6 +369,14 @@ def test_warn
assert_equal LEVEL_LABEL_MAP[Logger::WARN], msg.severity
end
+ def test_warn_eh
+ @logger.level = Logger::WARN
+ assert_equal true, @logger.warn?
+
+ @logger.level = Logger::ERROR
+ assert_equal false, @logger.warn?
+ end
+
def test_info
msg = log :info, 'info level message'
assert_equal LEVEL_LABEL_MAP[Logger::INFO], msg.severity
@@ -374,6 +406,14 @@ def test_info
assert_equal LEVEL_LABEL_MAP[Logger::INFO], msg.severity
end
+ def test_info_eh
+ @logger.level = Logger::INFO
+ assert_equal true, @logger.info?
+
+ @logger.level = Logger::WARN
+ assert_equal false, @logger.info?
+ end
+
def test_debug
msg = log :debug, 'debug level message'
assert_equal LEVEL_LABEL_MAP[Logger::DEBUG], msg.severity
@@ -403,6 +443,14 @@ def test_debug
assert_equal LEVEL_LABEL_MAP[Logger::DEBUG], msg.severity
end
+ def test_debug_eh
+ @logger.level = Logger::DEBUG
+ assert_equal true, @logger.debug?
+
+ @logger.level = Logger::INFO
+ assert_equal false, @logger.debug?
+ end
+
end
class TestSyslogLogger < TestLogger
Please sign in to comment.
Something went wrong with that request. Please try again.