lib/heavylog.rb in heavylog-0.0.5 vs lib/heavylog.rb in heavylog-0.0.6

- old
+ new

@@ -8,10 +8,12 @@ require 'heavylog/request_logger' module Heavylog module_function + TRUNCATION = '[TRUNCATED]'.freeze + mattr_accessor :logger, :application, :formatter, :log_level def setup(app) self.application = app patch_loggers @@ -57,10 +59,11 @@ end end def log(severity, message = nil, progname = nil, &block) return if !config.enabled + return if !!RequestStore.store[:heavylog_truncated] uuid = RequestStore.store[:heavylog_request_id] return if !uuid if message.nil? @@ -70,10 +73,17 @@ message = progname end end RequestStore.store[:heavylog_buffer] ||= StringIO.new - RequestStore.store[:heavylog_buffer].puts(message) + + if RequestStore.store[:heavylog_buffer].length + message.bytesize > config.message_limit + RequestStore.store[:heavylog_buffer].truncate(0) + RequestStore.store[:heavylog_buffer].puts(TRUNCATION) + RequestStore.store[:heavylog_truncated] = true + else + RequestStore.store[:heavylog_buffer].puts(message) + end end def finish return if !config.enabled