Class: Timber::Logger
- Inherits:
-
Logger
- Object
- Logger
- Timber::Logger
- Defined in:
- lib/timber/logger.rb
Overview
The Timber Logger behaves exactly like ::Logger, except that it supports a transparent API
for logging structured messages. It ensures your log messages are communicated properly
with the Timber.io API.
To adhere to our no code debt / no lock-in promise, the Timber Logger will never deviate
from the ::Logger interface. That is, it will never add methods, or alter any
method signatures. This ensures Timber can be removed without consequence.
Defined Under Namespace
Classes: HybridFormatter, JSONFormatter, PassThroughFormatter, SimpleFormatter
Class Method Summary collapse
Instance Method Summary collapse
- #formatter=(value) ⇒ Object
-
#initialize(*args) ⇒ Logger
constructor
Creates a new Timber::Logger instances.
Constructor Details
#initialize(*args) ⇒ Logger
Creates a new Timber::Logger instances. Accepts the same arguments as ::Logger.new.
The only difference is that it default the formatter to HybridFormatter. Using
a different formatter is easy. For example, if you prefer your logs in JSON.
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/timber/logger.rb', line 181 def initialize(*args) super(*args) # Ensure we sync STDOUT to avoid buffering if args.size == 1 and args.first.respond_to?(:"sync=") args.first.sync = true end if args.size == 1 and args.first.is_a?(LogDevices::HTTP) self.formatter = PassThroughFormatter.new else self.formatter = HybridFormatter.new end self.level = environment_level @initialized = true end |
Class Method Details
.new_from_config ⇒ Object
170 171 |
# File 'lib/timber/logger.rb', line 170 def new_from_config end |
Instance Method Details
#formatter=(value) ⇒ Object
200 201 202 203 204 205 206 207 208 |
# File 'lib/timber/logger.rb', line 200 def formatter=(value) if @initialized && @logdev && @logdev.dev.is_a?(Timber::LogDevices::HTTP) && !value.is_a?(PassThroughFormatter) raise ArgumentError.new("The formatter cannot be changed when using the " + "Timber::LogDevices::HTTP log device. The PassThroughFormatter must be used for proper " + "delivery.") end super end |