class QB::IPC::STDIO::Server::LogService::Log

Public Class Methods

new(**kwds) click to toggle source

Construction

Calls superclass method
# File lib/qb/ipc/stdio/server/log_service.rb, line 15
def initialize **kwds
  super *kwds.values_at( :name, :level, :level_index )
  
  if kwds.key? :timestamp
    self.time = Time.parse kwds[:timestamp]
  end
  
  self.tags = kwds[:tags] || []
  self.named_tags = kwds[:named_tags] || {}
  
  @pid = kwds[:pid] || '???'
  @thread = kwds[:thread] || '???'
  
  exception = if kwds.key? :exception
    klass = kwds[:exception]["name"].safe_constantize
    
    if klass
      # HACK  Good God...
      #
      #       What we're doing is constructing an instance of the
      #       exception class so that SemLog is happy with it... so we
      #       take the class name, load that constant, then we *don't*
      #       create an instance, because that could require args, and
      #       all we need is something that holds the message and
      #       backtrace, so we add the message as the response from
      #       dynamically-created `#to_s` and `#message` methods added
      #       *to that instance only*. Then we set the backtrace using
      #       the regular instance API.
      #
      #       ...and it kinda seems to work. But I suspect it will fuck
      #       me/us/someone at some point if left like this...
      #
      
      message = kwds[:exception]["message"] || '(none)'
      
      error = klass.allocate
      
      metaclass = class << error; self; end
      
      [:to_s, :message].each do |name|
        metaclass.send( :define_method, name ){ message }
      end
      
      if kwds[:exception]["stack_trace"]
        error.set_backtrace kwds[:exception]["stack_trace"]
      end
      
      error
    end
  end
  
  assign exception: exception, **kwds.slice(
    :message,
    :payload,
    :min_duration,
    :metric,
    :metric_amount,
    :duration,
    # :backtrace,
    # :log_exception,
    # :on_exception_level,
    :dimension,
  )
end

Public Instance Methods

process_info(thread_name_length = 30) click to toggle source

Instance Methods

# File lib/qb/ipc/stdio/server/log_service.rb, line 83
def process_info thread_name_length = 30
  "IPC:#{ @pid }:#{"%.#{ thread_name_length }s" % @thread}"
end