Class: QB::IPC::STDIO::Server::LogService::Log

Inherits:
SemanticLogger::Log
  • Object
show all
Defined in:
lib/qb/ipc/stdio/server/log_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(**kwds) ⇒ Log

Construction



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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

Instance Method Details

#process_info(thread_name_length = 30) ⇒ Object

Instance Methods



83
84
85
# 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