Class: TTY::Logger::Handlers::Stream
- Inherits:
-
Object
- Object
- TTY::Logger::Handlers::Stream
- Includes:
- Base
- Defined in:
- lib/tty/logger/handlers/stream.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #call(event) ⇒ Object
-
#initialize(output: $stderr, formatter: nil, config: nil, level: nil) ⇒ Stream
constructor
A new instance of Stream.
Methods included from Base
#coerce_formatter, #format_filepath, #log_at, #metadata, #raise_formatter_error
Constructor Details
#initialize(output: $stderr, formatter: nil, config: nil, level: nil) ⇒ Stream
Returns a new instance of Stream.
17 18 19 20 21 22 23 |
# File 'lib/tty/logger/handlers/stream.rb', line 17 def initialize(output: $stderr, formatter: nil, config: nil, level: nil) @output = Array[output].flatten @formatter = coerce_formatter(formatter || config.formatter).new @config = config @level = level || @config.level @mutex = Mutex.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/tty/logger/handlers/stream.rb', line 13 def config @config end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
15 16 17 |
# File 'lib/tty/logger/handlers/stream.rb', line 15 def level @level end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
11 12 13 |
# File 'lib/tty/logger/handlers/stream.rb', line 11 def output @output end |
Instance Method Details
#call(event) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tty/logger/handlers/stream.rb', line 26 def call(event) @mutex.lock data = {} .each do || case when :date data["date"] = event.[:time].strftime(config.date_format) when :time data["time"] = event.[:time].strftime(config.time_format) when :file data["path"] = format_filepath(event) when :pid data["pid"] = event.[:pid] else raise "Unknown metadata `#{}`" end end data["level"] = event.[:level] data["message"] = event..join(' ') unless event.fields.empty? data.merge!(event.fields) end unless event.backtrace.empty? data.merge!("backtrace" => event.backtrace.join(",")) end output.each do |out| out.puts @formatter.dump(data, max_bytes: config.max_bytes, max_depth: config.max_depth) end ensure @mutex.unlock end |