Class: NewRelic::Agent::AgentLogger

Inherits:
Object
  • Object
show all
Includes:
LogOnce
Defined in:
lib/new_relic/agent/agent_logger.rb

Constant Summary

Constants included from LogOnce

LogOnce::NUM_LOG_ONCE_KEYS

Instance Method Summary collapse

Methods included from LogOnce

#clear_already_logged, #log_once

Constructor Details

#initialize(root = '', override_logger = nil) ⇒ AgentLogger

Returns a new instance of AgentLogger.



16
17
18
19
20
21
22
23
24
25
# File 'lib/new_relic/agent/agent_logger.rb', line 16

def initialize(root = '', override_logger = nil)
  @already_logged_lock = Mutex.new
  clear_already_logged
  create_log(root, override_logger)
  set_log_level!
  set_log_format!
  disable_log_instrumentation!

  gather_startup_logs
end

Instance Method Details

#debug(*msgs, &blk) ⇒ Object



43
44
45
# File 'lib/new_relic/agent/agent_logger.rb', line 43

def debug(*msgs, &blk)
  format_and_send(:debug, msgs, &blk)
end

#error(*msgs, &blk) ⇒ Object



31
32
33
# File 'lib/new_relic/agent/agent_logger.rb', line 31

def error(*msgs, &blk)
  format_and_send(:error, msgs, &blk)
end

#fatal(*msgs, &blk) ⇒ Object



27
28
29
# File 'lib/new_relic/agent/agent_logger.rb', line 27

def fatal(*msgs, &blk)
  format_and_send(:fatal, msgs, &blk)
end

#info(*msgs, &blk) ⇒ Object



39
40
41
# File 'lib/new_relic/agent/agent_logger.rb', line 39

def info(*msgs, &blk)
  format_and_send(:info, msgs, &blk)
end

#is_startup_logger?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/new_relic/agent/agent_logger.rb', line 47

def is_startup_logger?
  @log.is_a?(NullLogger)
end

#log_exception(level, e, backtrace_level = level) ⇒ Object

Use this when you want to log an exception with explicit control over the log level that the backtrace is logged at. If you just want the default behavior of backtraces logged at debug, use one of the methods above and pass an Exception as one of the args.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/new_relic/agent/agent_logger.rb', line 55

def log_exception(level, e, backtrace_level = level)
  @log.send(level, '%p: %s' % [e.class, e.message])
  @log.send(backtrace_level) do
    backtrace = backtrace_from_exception(e)
    if backtrace
      "Debugging backtrace:\n" + backtrace.join("\n  ")
    else
      'No backtrace available.'
    end
  end
end

#log_formatter=(formatter) ⇒ Object



67
68
69
# File 'lib/new_relic/agent/agent_logger.rb', line 67

def log_formatter=(formatter)
  @log.formatter = formatter
end

#warn(*msgs, &blk) ⇒ Object



35
36
37
# File 'lib/new_relic/agent/agent_logger.rb', line 35

def warn(*msgs, &blk)
  format_and_send(:warn, msgs, &blk)
end