lib/liquid/logger.rb in liquid-ext-3.0.0 vs lib/liquid/logger.rb in liquid-ext-3.1.0
- old
+ new
@@ -12,10 +12,11 @@
def initialize(name, progname = nil)
@progname = progname || File.basename($0)
@logger = LoggerFactory.getLogger(name)
@exceptions = {}
+ @exception_handlers = [method(:_log_error_exception)]
root = org.apache.log4j.Logger.getRootLogger
appender = org.apache.log4j.ConsoleAppender.new
appender.name = "console"
appender.layout = org.apache.log4j.PatternLayout.new($conf.log.format)
appender.threshold = org.apache.log4j.Level.toLevel($conf.log.level.to_s)
@@ -72,10 +73,20 @@
return unless error?
args = yield if block_given?
@logger.error(format(*args))
end
+ def add_exception_handler(&block)
+ @exception_handlers << block
+ end
+
def exception(exc, message = nil, attribs = {})
+ @exception_handlers.each do |callback|
+ callback.call(exc, message, attribs)
+ end
+ end
+
+ def _log_error_exception(exc, message, attribs)
::Metrics.meter("exception:#{exc.class.to_s.tableize}").mark
@exceptions[exc.class] ||= {}
@exceptions[exc.class][exc.backtrace.first] ||= [System.nano_time, 1, 1]
five_minutes_ago = System.nano_time - 300_000_000_000
last, count, backoff = *@exceptions[exc.class][exc.backtrace.first]