Skip to content

Commit

Permalink
Keep track of the highest logged severity
Browse files Browse the repository at this point in the history
  • Loading branch information
paukul committed Aug 5, 2011
1 parent 6ccd301 commit e7bce30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/amqp_logging/metrics_agent.rb
Expand Up @@ -13,7 +13,8 @@ def initialize
:pid => Process.pid,
:loglines => {
:default => []
}
},
:severity => 0
}
@max_lines_per_logger = DEFAULT_MAX_LINES_PER_LOGGER
@logger_types = {}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -106,4 +108,4 @@ def add_with_proxy(severity, message = nil, progname = nil)
end
end
end
end
end
9 changes: 9 additions & 0 deletions test/metrics_agent_test.rb
Expand Up @@ -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)
Expand Down

0 comments on commit e7bce30

Please sign in to comment.