Module: Telemetry::Logger::Methods

Included in:
Telemetry::Logger
Defined in:
lib/telemetry/logger/methods.rb

Instance Method Summary collapse

Instance Method Details

#colorizeObject



6
7
8
9
10
11
12
13
14
# File 'lib/telemetry/logger/methods.rb', line 6

def colorize
  @colorize ||= if opts[:logfile].is_a?(String)
                  false
                elsif opts.key? :color
                  opts[:color]
                else
                  true
                end
end

#debug(message = nil) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/telemetry/logger/methods.rb', line 16

def debug(message = nil)
  return unless log.level < 1

  message = yield if message.nil? && block_given?
  message = Rainbow(message).blue if colorize
  log.debug(message)
end

#error(message = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/telemetry/logger/methods.rb', line 40

def error(message = nil)
  return unless log.level < 4

  message = yield if message.nil? && block_given?
  message = Rainbow(message).red if colorize
  log.error(message)
end

#fatal(message = nil) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/telemetry/logger/methods.rb', line 48

def fatal(message = nil)
  return unless log.level < 5

  message = yield if message.nil? && block_given?
  message = Rainbow(message).darkred if colorize
  log.fatal(message)
end

#info(message = nil) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/telemetry/logger/methods.rb', line 24

def info(message = nil)
  return unless log.level < 2

  message = yield if message.nil? && block_given?
  message = Rainbow(message).green if colorize
  log.info(message)
end

#thread(kvl: false, **_opts) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/telemetry/logger/methods.rb', line 62

def thread(kvl: false, **_opts)
  if kvl
    "thread=#{Thread.current.object_id}"
  else
    Thread.current.object_id.to_s
  end
end

#unknown(message = nil) ⇒ Object



56
57
58
59
60
# File 'lib/telemetry/logger/methods.rb', line 56

def unknown(message = nil)
  message = yield if message.nil? && block_given?
  message = Rainbow(message).purple if colorize
  log.unknown(message)
end

#warn(message = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/telemetry/logger/methods.rb', line 32

def warn(message = nil)
  return unless log.level < 3

  message = yield if message.nil? && block_given?
  message = Rainbow(message).yellow if colorize
  log.warn(message)
end