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, MsgPackFormatter
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.
155 156 157 158 159 160 161 162 |
# File 'lib/timber/logger.rb', line 155 def initialize(*args) super(*args) if args.size == 1 and args.first.is_a?(LogDevices::HTTP) self.formatter = MsgPackFormatter.new else self.formatter = HybridFormatter.new end end |
Instance Method Details
#formatter=(value) ⇒ Object
164 165 166 167 168 169 170 171 |
# File 'lib/timber/logger.rb', line 164 def formatter=(value) if @dev.is_a?(Timber::LogDevices::HTTP) raise ArgumentError.new("The formatter cannot be changed when using the " + "Timber::LogDevices::HTTP log device. The MsgPackFormatter must be used for proper " + "delivery.") end super end |