Class: StackifyRubyAPM::Spies::LoggerSpy Private

Inherits:
Object
  • Object
show all
Defined in:
lib/stackify_apm/spies/logger.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

NAME =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'logger'
TYPE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'core.devlog'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_log_context(severity, message, progname) ⇒ Object

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.

create and return logger span context



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/stackify_apm/spies/logger.rb', line 72

def self.get_log_context(severity, message, progname)
  ctx = nil

  begin
    log_message = ''
    exception = nil

    if message.nil?
      msg = progname
    else
      msg = message
    end

    case msg
    when ::String
      log_message = msg
    when ::Exception
      log_message = msg.message
      exception = "(#{ msg.class })\n#{ msg.backtrace.join("\n") if msg.backtrace }"
    else
      log_message = msg.inspect
    end

    ctx = Span::Context.new(
      CATEGORY: 'Log',
      SUBCATEGORY: 'Logger',
      LEVEL: severity || 'ANY',
      MESSAGE: log_message,
      PREFIX: 'TRUE'
    )

    if exception
      ctx.EXCEPTION = exception
    end
  rescue Exception => e
    StackifyRubyAPM.agent.error "[LoggerSpy] Error: creating span context."
    StackifyRubyAPM.agent.error "[LoggerSpy] #{e.inspect}"
  end

  ctx
end

Instance Method Details

#installObject

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.



12
13
14
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
# File 'lib/stackify_apm/spies/logger.rb', line 12

def install
  Logger.class_eval do
    alias_method 'debug_without_apm', 'debug'
    alias_method 'info_without_apm', 'info'
    alias_method 'warn_without_apm', 'warn'
    alias_method 'error_without_apm', 'error'
    alias_method 'fatal_without_apm', 'fatal'
    alias_method 'unknown_without_apm', 'unknown'

    def debug(progname = nil, &block)
      return debug_without_apm(progname, &block) unless StackifyRubyAPM.current_transaction
      ctx = StackifyRubyAPM::Spies::LoggerSpy.get_log_context('DEBUG', nil, progname, &block)
      StackifyRubyAPM.span NAME, TYPE, context: ctx do
        debug_without_apm(progname, &block)
      end
    end

    def info(progname = nil, &block)
      return info_without_apm(progname, &block) unless StackifyRubyAPM.current_transaction
      ctx = StackifyRubyAPM::Spies::LoggerSpy.get_log_context('INFO', nil, progname, &block)
      StackifyRubyAPM.span NAME, TYPE, context: ctx do
        info_without_apm(progname, &block)
      end
    end

    def warn(progname = nil, &block)
      return warn_without_apm(progname, &block) unless StackifyRubyAPM.current_transaction
      ctx = StackifyRubyAPM::Spies::LoggerSpy.get_log_context('WARN', nil, progname, &block)
      StackifyRubyAPM.span NAME, TYPE, context: ctx do
        warn_without_apm(progname, &block)
      end
    end

    def error(progname = nil, &block)
      return error_without_apm(progname, &block) unless StackifyRubyAPM.current_transaction
      ctx = StackifyRubyAPM::Spies::LoggerSpy.get_log_context('ERROR', nil, progname, &block)
      StackifyRubyAPM.span NAME, TYPE, context: ctx do
        error_without_apm(progname, &block)
      end
    end

    def fatal(progname = nil, &block)
      return fatal_without_apm(progname, &block) unless StackifyRubyAPM.current_transaction
      ctx = StackifyRubyAPM::Spies::LoggerSpy.get_log_context('FATAL', nil, progname, &block)
      StackifyRubyAPM.span NAME, TYPE, context: ctx do
        fatal_without_apm(progname, &block)
      end
    end

    def unknown(progname = nil, &block)
      return unknown_without_apm(progname, &block) unless StackifyRubyAPM.current_transaction
      ctx = StackifyRubyAPM::Spies::LoggerSpy.get_log_context('UNKNOWN', nil, progname, &block)
      StackifyRubyAPM.span NAME, TYPE, context: ctx do
        unknown_without_apm(progname, &block)
      end
    end
  end
end