Class: Logbert::Handlers::StreamHandler

Inherits:
BaseHandler show all
Defined in:
lib/logbert/handlers/stream_handler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#formatter, #formatter=, #publish

Constructor Details

#initialize(stream = $stderr) ⇒ StreamHandler

Returns a new instance of StreamHandler.



12
13
14
# File 'lib/logbert/handlers/stream_handler.rb', line 12

def initialize(stream = $stderr)
  @stream = stream
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



10
11
12
# File 'lib/logbert/handlers/stream_handler.rb', line 10

def stream
  @stream
end

Class Method Details

.for_path(path) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/logbert/handlers/stream_handler.rb', line 16

def self.for_path(path)
  dirname = File.dirname(File.absolute_path(path))
  FileUtils.mkdir_p dirname unless File.exists? dirname

  fout = File.open(path, "ab")
  StreamHandler.new fout
end

Instance Method Details

#emit(output) ⇒ Object



25
26
27
28
# File 'lib/logbert/handlers/stream_handler.rb', line 25

def emit(output)
  @stream.puts output
  @stream.flush
end