Class: Fluent::Logger::ConsoleLogger

Inherits:
TextLogger show all
Defined in:
lib/fluent/logger/console_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from TextLogger

#post_with_time

Methods inherited from LoggerBase

open, #post

Constructor Details

#initialize(out) ⇒ ConsoleLogger

Returns a new instance of ConsoleLogger



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fluent/logger/console_logger.rb', line 23

def initialize(out)
  super()
  require 'time'

  if out.is_a?(String)
    @io = File.open(out, "a")
    @on_reopen = Proc.new { @io.reopen(out, "a") }
  elsif out.respond_to?(:write)
    @io = out
    @on_reopen = Proc.new { }
  else
    raise "Invalid output: #{out.inspect}"
  end
end

Instance Attribute Details

#time_formatObject

Returns the value of attribute time_format



38
39
40
# File 'lib/fluent/logger/console_logger.rb', line 38

def time_format
  @time_format
end

Instance Method Details

#closeObject



48
49
50
51
# File 'lib/fluent/logger/console_logger.rb', line 48

def close
  @io.close unless @io == STDOUT
  self
end

#post_text(text) ⇒ Object



44
45
46
# File 'lib/fluent/logger/console_logger.rb', line 44

def post_text(text)
  @io.puts text
end

#reopen!Object



40
41
42
# File 'lib/fluent/logger/console_logger.rb', line 40

def reopen!
  @on_reopen.call
end