Class: LogjamAgent::BufferedLogger

Inherits:
ActiveSupport::Logger show all
Includes:
RequestHandling
Defined in:
lib/logjam_agent/buffered_logger.rb

Instance Method Summary collapse

Methods included from RequestHandling

#finish_request, #request, #request=, #start_request

Methods inherited from ActiveSupport::Logger

broadcast, original_broadcast

Constructor Details

#initialize(*args) ⇒ BufferedLogger

Returns a new instance of BufferedLogger.



36
37
38
39
40
# File 'lib/logjam_agent/buffered_logger.rb', line 36

def initialize(*args)
  super(*args)
  # make sure we always have a formatter
  self.formatter = Logger::Formatter.new
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/logjam_agent/buffered_logger.rb', line 47

def add(severity, message = nil, progname = nil, &block)
  return if level > severity
  message = progname if message.nil?
  progname = nil
  message ||= block.call || '' if block
  request = LogjamAgent.request
  logjam_message = format_message_for_logjam(message, request, severity)
  time = Time.now
  request.add_line(severity, time, logjam_message) if request && !SelectiveLogging.logdevice_only?
  log_to_log_device = LogjamAgent.log_to_log_device?(severity, logjam_message)
  log_to_log_device = false if request && request.ignored?
  if log_to_log_device && !SelectiveLogging.logjam_only?
    device_message = format_message_for_log_device(message)
    formatted_message = formatter.call(format_severity(severity), time, progname, device_message)
    @logdev.write(formatted_message) if @logdev
  end
  message
end

#formatter=(formatter) ⇒ Object



42
43
44
45
# File 'lib/logjam_agent/buffered_logger.rb', line 42

def formatter=(formatter)
  super
  @formatter.extend LoggingAttributes
end

#logdev=(log_device) ⇒ Object



66
67
68
69
# File 'lib/logjam_agent/buffered_logger.rb', line 66

def logdev=(log_device)
  raise "cannot connect logger to new log device" unless log_device.respond_to?(:write)
  @logdev = log_device
end