Class: Debugbar::SimpleLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/debugbar/loggers/simple_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(min_level = 2) ⇒ SimpleLogger

Returns a new instance of SimpleLogger.



3
4
5
# File 'lib/debugbar/loggers/simple_logger.rb', line 3

def initialize(min_level= 2)
  @min_level = min_level
end

Instance Method Details

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/debugbar/loggers/simple_logger.rb', line 7

def add(severity, message = nil, progname = nil)
  # We normally rely on the Tracker to know if the current request is set or nil and log an error to STDOUT,
  # but in this case, it happens so often that the logs are annoying.
  # In ActiveCable, only the first call goes through the Rake middleware, so every following communication
  # doesn't go through TrackCurrentRequest, which initializes the request.
  return if ::Debugbar::Current.request.nil?

  return if severity < @min_level

  if message.nil?
    if block_given?
      message = yield
    else
      message = progname
      progname = nil
    end
  end

  Debugbar::Tracker.add_log({
    time: Time.now.strftime(Debugbar::TIME_FORMAT),
    severity: severity,
    severity_label: SEV_LABEL[severity],
    message: message,
    progname: progname,
  })
end