Permalink
Browse files

Keep track of the highest logged severity

  • Loading branch information...
1 parent 6ccd301 commit e7bce3061b6ce3eca1640414ee39eab6801379bb @paukul committed Aug 5, 2011
Showing with 13 additions and 2 deletions.
  1. +4 −2 lib/amqp_logging/metrics_agent.rb
  2. +9 −0 test/metrics_agent_test.rb
@@ -13,7 +13,8 @@ def initialize
:pid => Process.pid,
:loglines => {
:default => []
- }
+ },
+ :severity => 0
}
@max_lines_per_logger = DEFAULT_MAX_LINES_PER_LOGGER
@logger_types = {}
@@ -47,6 +48,7 @@ def add_logline(severity, message, progname, logger)
timestring = AMQPLogging.iso_time_with_microseconds
logtype = @logger_types[logger]
lines = @fields[:loglines][logtype]
+ self[:severity] = severity if self[:severity] < severity
if !@truncated_status[logtype] && lines.size < @max_lines_per_logger
msg = (message || progname).strip
lines << [severity, timestring, msg]
@@ -106,4 +108,4 @@ def add_with_proxy(severity, message = nil, progname = nil)
end
end
end
-end
+end
@@ -93,6 +93,15 @@ def setup
assert_equal some_logline, message
end
+ test "should keep track of the highest log severity" do
+ @proxy.debug "foo"
+ assert_equal Logger::DEBUG, @agent[:severity]
+ @proxy.warn "bar"
+ assert_equal Logger::WARN, @agent[:severity]
+ @proxy.debug "baz"
+ assert_equal Logger::WARN, @agent[:severity]
+ end
+
test "should allow to register multiple loggers with different types" do
other_logger = ::Logger.new('/dev/null')
@agent.wrap_logger(other_logger, :sql)

0 comments on commit e7bce30

Please sign in to comment.