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
debuglevel. -
#debug? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::DEBUG to be written, false otherwise.
-
#error { ... } ⇒ void
Logs a message with the
errorlevel. -
#error? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::ERROR to be written, false otherwise.
-
#fatal { ... } ⇒ void
Logs a message with the
fatallevel. -
#fatal? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::FATAL to be written, false otherwise.
-
#info { ... } ⇒ void
Logs a message with the
infolevel. -
#info? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::INFO to be written, false otherwise.
-
#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
warnlevel. -
#warn? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::WARN to be written, false otherwise.
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 |
#debug? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::DEBUG to be written, false otherwise.
97 98 99 |
# File 'lib/ductr/log/logger.rb', line 97 def debug? self.class.level <= ::Logger::DEBUG end |
#error { ... } ⇒ void
This method returns an undefined value.
Logs a message with the error level.
154 155 156 |
# File 'lib/ductr/log/logger.rb', line 154 def error(...) write(::Logger::ERROR, ...) end |
#error? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::ERROR to be written, false otherwise.
163 164 165 |
# File 'lib/ductr/log/logger.rb', line 163 def error? self.class.level <= ::Logger::ERROR end |
#fatal { ... } ⇒ void
This method returns an undefined value.
Logs a message with the fatal level.
176 177 178 |
# File 'lib/ductr/log/logger.rb', line 176 def fatal(...) write(::Logger::FATAL, ...) end |
#fatal? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::FATAL to be written, false otherwise.
185 186 187 |
# File 'lib/ductr/log/logger.rb', line 185 def fatal? self.class.level <= ::Logger::FATAL end |
#info { ... } ⇒ void
This method returns an undefined value.
Logs a message with the info level.
110 111 112 |
# File 'lib/ductr/log/logger.rb', line 110 def info(...) write(::Logger::INFO, ...) end |
#info? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::INFO to be written, false otherwise.
119 120 121 |
# File 'lib/ductr/log/logger.rb', line 119 def info? self.class.level <= ::Logger::INFO end |
#warn { ... } ⇒ void
This method returns an undefined value.
Logs a message with the warn level.
132 133 134 |
# File 'lib/ductr/log/logger.rb', line 132 def warn(...) write(::Logger::WARN, ...) end |
#warn? ⇒ Boolean
Returns true if the log level allows entries with severity Logger::WARN to be written, false otherwise.
141 142 143 |
# File 'lib/ductr/log/logger.rb', line 141 def warn? self.class.level <= ::Logger::WARN end |