Class: Ougai::Logger
- Inherits:
-
Logger
- Object
- Logger
- Ougai::Logger
- Includes:
- Logging
- Defined in:
- lib/ougai/logger.rb
Overview
Main Logger
Constant Summary
Constants included from Ougai::Logging::Severity
Ougai::Logging::Severity::SEV_LABEL, Ougai::Logging::Severity::TRACE
Instance Attribute Summary collapse
-
#before_log ⇒ Proc
Hook before logging.
-
#default_message ⇒ String
Use this if log message is not specified (by default this is ‘No message’).
-
#exc_key ⇒ String
The field name of Exception (by default this is :err).
-
#with_fields ⇒ Hash
The fields appending to all logs.
Class Method Summary collapse
-
.broadcast(logger) ⇒ Object
Broadcasts the same logs to the another logger.
Instance Method Summary collapse
- #chain(severity, args, fields, hooks) ⇒ Object
-
#initialize(*args) ⇒ Logger
constructor
A new instance of Logger.
- #level=(severity) ⇒ Object
Methods included from Logging
#child, #debug, #error, #fatal, #info, #trace, #trace?, #unknown, #warn
Methods included from Ougai::Logging::Severity
Constructor Details
#initialize(*args) ⇒ Logger
Returns a new instance of Logger.
12 13 14 15 16 17 18 |
# File 'lib/ougai/logger.rb', line 12 def initialize(*args) super(*args) @default_message = 'No message' @exc_key = :err @with_fields = {} @formatter = create_formatter end |
Instance Attribute Details
#before_log ⇒ Proc
Hook before logging.
7 8 9 |
# File 'lib/ougai/logger.rb', line 7 def before_log @before_log end |
#default_message ⇒ String
Use this if log message is not specified (by default this is ‘No message’).
7 8 9 |
# File 'lib/ougai/logger.rb', line 7 def @default_message end |
#exc_key ⇒ String
The field name of Exception (by default this is :err).
7 8 9 |
# File 'lib/ougai/logger.rb', line 7 def exc_key @exc_key end |
#with_fields ⇒ Hash
The fields appending to all logs.
7 8 9 |
# File 'lib/ougai/logger.rb', line 7 def with_fields @with_fields end |
Class Method Details
.broadcast(logger) ⇒ Object
Broadcasts the same logs to the another logger
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ougai/logger.rb', line 22 def self.broadcast(logger) Module.new do |mdl| ::Logger::Severity.constants.each do |severity| method_name = severity.downcase.to_sym mdl.send(:define_method, method_name) do |*args| logger.send(method_name, *args) super(*args) end end define_method(:level=) do |level| logger.level = level super(level) end define_method(:close) do logger.close super() end end end |
Instance Method Details
#chain(severity, args, fields, hooks) ⇒ Object
60 61 62 63 |
# File 'lib/ougai/logger.rb', line 60 def chain(severity, args, fields, hooks) hooks.push(@before_log) if @before_log write(severity, args, merge_fields(@with_fields, fields), hooks) end |
#level=(severity) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ougai/logger.rb', line 45 def level=(severity) if severity.is_a?(Integer) @level = severity return end if severity.to_s.downcase == 'trace' @level = TRACE return end super end |