Class: Ougai::ChildLogger

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/ougai/child_logger.rb

Overview

A logger created by the ‘child` method of parent logger

Constant Summary

Constants included from Logging::Severity

Logging::Severity::SEV_LABEL, Logging::Severity::TRACE

Instance Attribute Summary

Attributes included from Logging

#before_log, #with_fields

Instance Method Summary collapse

Methods included from Logging

#_log, #add, #debug, #error, #fatal, #info, #trace, #trace?, #unknown, #warn

Methods included from Logging::Severity

#from_label, #to_label

Constructor Details

#initialize(parent, fields) ⇒ ChildLogger

Returns a new instance of ChildLogger.



9
10
11
12
13
14
# File 'lib/ougai/child_logger.rb', line 9

def initialize(parent, fields)
  @before_log = nil
  @level = nil
  @parent = parent
  @with_fields = fields
end

Instance Method Details

#chain(severity, args, fields, hooks) ⇒ Object



82
83
84
85
# File 'lib/ougai/child_logger.rb', line 82

def chain(severity, args, fields, hooks)
  hooks.push(@before_log) if @before_log
  @parent.chain(severity, args, weak_merge!(fields, @with_fields), hooks)
end

#child(fields = {}) ⇒ ChildLogger

Creates a child logger and returns it.

Parameters:

  • fields (Hash) (defaults to: {})

    The fields appending to all logs

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/ougai/child_logger.rb', line 19

def child(fields = {})
  ch = self.class.new(self, fields)

  if !block_given?
    ch
  else
    yield ch
  end
end

#debug?Boolean

Whether the current severity level allows for logging DEBUG.

Returns:

  • (Boolean)

    true if allows



53
54
55
# File 'lib/ougai/child_logger.rb', line 53

def debug?
  level <= DEBUG
end

#error?Boolean

Whether the current severity level allows for logging ERROR.

Returns:

  • (Boolean)

    true if allows



71
72
73
# File 'lib/ougai/child_logger.rb', line 71

def error?
  level <= ERROR
end

#fatal?Boolean

Whether the current severity level allows for logging FATAL.

Returns:

  • (Boolean)

    true if allows



77
78
79
# File 'lib/ougai/child_logger.rb', line 77

def fatal?
  level <= FATAL
end

#info?Boolean

Whether the current severity level allows for logging INFO.

Returns:

  • (Boolean)

    true if allows



59
60
61
# File 'lib/ougai/child_logger.rb', line 59

def info?
  level <= INFO
end

#levelObject Also known as: sev_threshold



44
45
46
# File 'lib/ougai/child_logger.rb', line 44

def level
  @level || @parent.level
end

#level=(severity) ⇒ Object Also known as: sev_threshold=

Set logging severity threshold. Note that the log level below parent one does not work.

Parameters:

  • severity (Integer|String|Symbol)

    The Severity of the log message.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ougai/child_logger.rb', line 32

def level=(severity)
  if severity.is_a?(Integer)
    @level = severity
  elsif severity.is_a?(String)
    @level = from_label(severity.upcase)
  elsif severity.is_a?(Symbol)
    @level = from_label(severity.to_s.upcase)
  else
    @level = nil
  end
end

#warn?Boolean

Whether the current severity level allows for logging WARN.

Returns:

  • (Boolean)

    true if allows



65
66
67
# File 'lib/ougai/child_logger.rb', line 65

def warn?
  level <= WARN
end