Class: Appsignal::Logger
Overview
Logger that flushes logs to the AppSignal logging service
Constant Summary collapse
- PLAINTEXT =
 0- LOGFMT =
 1- JSON =
 2- SEVERITY_MAP =
 { DEBUG => 2, INFO => 3, WARN => 5, ERROR => 6, FATAL => 7 }.freeze
Instance Method Summary collapse
- 
  
    
      #add(severity, message = nil, group = nil)  ⇒ Object 
    
    
      (also: #log)
    
  
  
  
  
  
  
  
  private
  
    
We support the various methods in the Ruby logger class by supplying this method.
 - 
  
    
      #debug(message = nil, attributes = {})  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Log a debug level message.
 - 
  
    
      #error(message = nil, attributes = {})  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Log an error level message.
 - 
  
    
      #fatal(message = nil, attributes = {})  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Log a fatal level message.
 - 
  
    
      #info(message = nil, attributes = {})  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Log an info level message.
 - 
  
    
      #initialize(group, level: INFO, format: PLAINTEXT)  ⇒ void 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Create a new logger instance.
 - 
  
    
      #warn(message = nil, attributes = {})  ⇒ void 
    
    
  
  
  
  
  
  
  
  
  
    
Log a warn level message.
 
Constructor Details
#initialize(group, level: INFO, format: PLAINTEXT) ⇒ void
Create a new logger instance
      26 27 28 29 30 31 32  | 
    
      # File 'lib/appsignal/logger.rb', line 26 def initialize(group, level: INFO, format: PLAINTEXT) raise TypeError, "group must be a string" unless group.is_a? String @group = group @level = level @format = format @mutex = Mutex.new end  | 
  
Instance Method Details
#add(severity, message = nil, group = nil) ⇒ Object Also known as: log
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
We support the various methods in the Ruby logger class by supplying this method.
      37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59  | 
    
      # File 'lib/appsignal/logger.rb', line 37 def add(severity, = nil, group = nil) severity ||= UNKNOWN return true if severity < level group = @group if group.nil? if .nil? if block_given? = yield else = progname group = @group end end return if .nil? = formatter.call(severity, Time.now, group, ) if formatter Appsignal::Extension.log( group, SEVERITY_MAP.fetch(severity, 0), @format, , Appsignal::Utils::Data.generate(appsignal_attributes) ) end  | 
  
#debug(message = nil, attributes = {}) ⇒ void
This method returns an undefined value.
Log a debug level message
      66 67 68 69 70 71  | 
    
      # File 'lib/appsignal/logger.rb', line 66 def debug( = nil, attributes = {}) return if DEBUG < level = yield if .nil? && block_given? return if .nil? add_with_attributes(DEBUG, , @group, attributes) end  | 
  
#error(message = nil, attributes = {}) ⇒ void
This method returns an undefined value.
Log an error level message
      99 100 101 102 103 104  | 
    
      # File 'lib/appsignal/logger.rb', line 99 def error( = nil, attributes = {}) return if ERROR < level = yield if .nil? && block_given? return if .nil? add_with_attributes(ERROR, , @group, attributes) end  | 
  
#fatal(message = nil, attributes = {}) ⇒ void
This method returns an undefined value.
Log a fatal level message
      110 111 112 113 114 115  | 
    
      # File 'lib/appsignal/logger.rb', line 110 def fatal( = nil, attributes = {}) return if FATAL < level = yield if .nil? && block_given? return if .nil? add_with_attributes(FATAL, , @group, attributes) end  | 
  
#info(message = nil, attributes = {}) ⇒ void
This method returns an undefined value.
Log an info level message
      77 78 79 80 81 82  | 
    
      # File 'lib/appsignal/logger.rb', line 77 def info( = nil, attributes = {}) return if INFO < level = yield if .nil? && block_given? return if .nil? add_with_attributes(INFO, , @group, attributes) end  | 
  
#warn(message = nil, attributes = {}) ⇒ void
This method returns an undefined value.
Log a warn level message
      88 89 90 91 92 93  | 
    
      # File 'lib/appsignal/logger.rb', line 88 def warn( = nil, attributes = {}) return if WARN < level = yield if .nil? && block_given? return if .nil? add_with_attributes(WARN, , @group, attributes) end  |