Class: DohLogger::IOStreamAcceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/doh/logger/iostream_acceptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ios = nil, format = nil, error_format = nil) ⇒ IOStreamAcceptor

Returns a new instance of IOStreamAcceptor.



7
8
9
10
11
# File 'lib/doh/logger/iostream_acceptor.rb', line 7

def initialize(ios = nil, format = nil, error_format = nil)
  @ios = ios || STDOUT
  @standard_formatter = format ? Formatter.new(format) : OptimizedStandardFormatter.new
  @error_formatter = Formatter.new(error_format || format || "%datetime [%severity] (%location) : %msg\nexception: %exception\nstack:\n%call_stack")
end

Instance Attribute Details

#iosObject (readonly)

Returns the value of attribute ios.



6
7
8
# File 'lib/doh/logger/iostream_acceptor.rb', line 6

def ios
  @ios
end

Instance Method Details

#flush_always(flag = true) ⇒ Object



13
14
15
# File 'lib/doh/logger/iostream_acceptor.rb', line 13

def flush_always(flag = true)
  @flush = flag
end

#log(event) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/doh/logger/iostream_acceptor.rb', line 17

def log(event)
  if event.severity >= ERROR
    curr_formatter = @error_formatter
  else
    curr_formatter = @standard_formatter
  end
  @ios.puts(curr_formatter.replace(event))
  @ios.fsync if @flush
end