Sha256: 7ac4345c3fadd7b0fc86d8b60bdffd4f556ea0a41499857b18de169702a2c7d5
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
require File.join(File.dirname(__FILE__), "io", "formatter") require File.join(File.dirname(__FILE__), "io", "hybrid_formatter") require File.join(File.dirname(__FILE__), "io", "hybrid_hidden_formatter") require File.join(File.dirname(__FILE__), "io", "json_formatter") require File.join(File.dirname(__FILE__), "io", "logfmt_formatter") module Timber module LogDevices # The purpose of a Timber log device is to take the raw log message and enrich it # with the current context. # # The IO log device works with any IO object. That is, any object that # response to #write(message). class IO < LogDevice attr_reader :formatter # Instantiates a new Timber IO log device. # # @param io [IO] any object the responds to #write(message) def initialize(io = STDOUT, options = {}) io.sync = true if io.respond_to?(:sync=) # ensures logs are written immediately instead of being buffered by ruby @formatter = options[:formatter] || HybridHiddenFormatter.new @io = io end def close(*_args) io.close end private def write_log_line(log_line) formatted_message = formatter.format(log_line) io.write(formatted_message + "\n") end def io @io end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
timberio-1.0.0.beta1 | lib/timber/log_devices/io.rb |