Class: Ductr::Log::Logger
- Inherits:
-
Object
- Object
- Ductr::Log::Logger
- Defined in:
- lib/ductr/log/logger.rb
Overview
A ractor compatible logger to be used inside jobs or anywhere else in your ductr project.
Class Method Summary collapse
-
.add_output(output, formatter = ::Logger::Formatter, **options) ⇒ void
Allows to add another log output.
-
.level ⇒ Integer
The current logging level, default ::Logger::DEBUG.
-
.level=(lvl) ⇒ void
Configure the logging level.
-
.outputs ⇒ Array<Array<StandardOutput, Array<::Logger::Formatter, Hash>>>
The configured outputs list.
Instance Method Summary collapse
-
#debug { ... } ⇒ void
Logs a message with the ‘debug` level.
-
#error { ... } ⇒ void
Logs a message with the ‘error` level.
-
#fatal { ... } ⇒ void
Logs a message with the ‘fatal` level.
-
#info { ... } ⇒ void
Logs a message with the ‘info` level.
-
#initialize(prog_name = nil) ⇒ Logger
constructor
Create configured outputs instances, meaning that you can’t add outputs in an already instantiated logger.
-
#warn { ... } ⇒ void
Logs a message with the ‘warn` level.
Constructor Details
#initialize(prog_name = nil) ⇒ Logger
Create configured outputs instances, meaning that you can’t add outputs in an already instantiated logger.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ductr/log/logger.rb', line 68 def initialize(prog_name = nil) @prog_name = prog_name @outputs = self.class.outputs.map do |output_with_params| out, params = *output_with_params formatter, = *params out.new(formatter, ** || {}) end end |
Class Method Details
.add_output(output, formatter = ::Logger::Formatter, **options) ⇒ void
This method returns an undefined value.
Allows to add another log output. Making possible to write logs in multiple places at the same time, e.g. in STDOUT and in logs files
22 23 24 25 |
# File 'lib/ductr/log/logger.rb', line 22 def add_output(output, formatter = ::Logger::Formatter, **) @outputs ||= [] @outputs.push([output, [formatter, ]]) end |
.level ⇒ Integer
Returns The current logging level, default ::Logger::DEBUG.
60 61 62 |
# File 'lib/ductr/log/logger.rb', line 60 def level @level || ::Logger::DEBUG end |
.level=(lvl) ⇒ void
This method returns an undefined value.
Configure the logging level.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ductr/log/logger.rb', line 44 def level=(lvl) level_sym = lvl.to_s.downcase.to_sym @level = { debug: ::Logger::DEBUG, info: ::Logger::INFO, warn: ::Logger::WARN, error: ::Logger::ERROR, fatal: ::Logger::FATAL }[level_sym] raise ArgumentError, "invalid log level: #{lvl}" unless @level end |
.outputs ⇒ Array<Array<StandardOutput, Array<::Logger::Formatter, Hash>>>
The configured outputs list
33 34 35 |
# File 'lib/ductr/log/logger.rb', line 33 def outputs @outputs || [[StandardOutput, [::Logger::Formatter]]] end |
Instance Method Details
#debug { ... } ⇒ void
This method returns an undefined value.
Logs a message with the ‘debug` level.
88 89 90 |
# File 'lib/ductr/log/logger.rb', line 88 def debug(...) write(::Logger::DEBUG, ...) end |
#error { ... } ⇒ void
This method returns an undefined value.
Logs a message with the ‘error` level.
127 128 129 |
# File 'lib/ductr/log/logger.rb', line 127 def error(...) write(::Logger::ERROR, ...) end |
#fatal { ... } ⇒ void
This method returns an undefined value.
Logs a message with the ‘fatal` level.
140 141 142 |
# File 'lib/ductr/log/logger.rb', line 140 def fatal(...) write(::Logger::FATAL, ...) end |
#info { ... } ⇒ void
This method returns an undefined value.
Logs a message with the ‘info` level.
101 102 103 |
# File 'lib/ductr/log/logger.rb', line 101 def info(...) write(::Logger::INFO, ...) end |
#warn { ... } ⇒ void
This method returns an undefined value.
Logs a message with the ‘warn` level.
114 115 116 |
# File 'lib/ductr/log/logger.rb', line 114 def warn(...) write(::Logger::WARN, ...) end |