Class: Ougai::ChildLogger
- Inherits:
-
Object
- Object
- Ougai::ChildLogger
- 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
Instance Method Summary collapse
- #chain(severity, args, fields, hooks) ⇒ Object
-
#child(fields = {}) ⇒ ChildLogger
Creates a child logger and returns it.
-
#debug? ⇒ Boolean
Whether the current severity level allows for logging DEBUG.
-
#error? ⇒ Boolean
Whether the current severity level allows for logging ERROR.
-
#fatal? ⇒ Boolean
Whether the current severity level allows for logging FATAL.
-
#info? ⇒ Boolean
Whether the current severity level allows for logging INFO.
-
#initialize(parent, fields) ⇒ ChildLogger
constructor
A new instance of ChildLogger.
- #level ⇒ Object (also: #sev_threshold)
-
#level=(severity) ⇒ Object
(also: #sev_threshold=)
Set logging severity threshold.
-
#warn? ⇒ Boolean
Whether the current severity level allows for logging WARN.
Methods included from Logging
#_log, #add, #debug, #error, #fatal, #info, #trace, #trace?, #unknown, #warn
Methods included from Logging::Severity
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.
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.
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.
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.
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.
59 60 61 |
# File 'lib/ougai/child_logger.rb', line 59 def info? level <= INFO end |
#level ⇒ Object 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.
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.
65 66 67 |
# File 'lib/ougai/child_logger.rb', line 65 def warn? level <= WARN end |