Class: YleTf::System::OutputLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/yle_tf/system/output_logger.rb

Direct Known Subclasses

TfHookOutputLogger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level) ⇒ OutputLogger

Returns a new instance of OutputLogger.

Raises:



10
11
12
13
14
# File 'lib/yle_tf/system/output_logger.rb', line 10

def initialize(level)
  @level = level.to_sym

  raise YleTf::Error, "Unknown log level '#{@level}'" if !level?(@level)
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



8
9
10
# File 'lib/yle_tf/system/output_logger.rb', line 8

def level
  @level
end

Instance Method Details

#call(io, progname) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/yle_tf/system/output_logger.rb', line 16

def call(io, progname)
  Thread.new do
    begin
      io.each { |line| log(progname, line.chomp) }
    rescue IOError => e
      YleTf::Logger.debug e.full_message
    end
  end
end

#level?(level) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/yle_tf/system/output_logger.rb', line 26

def level?(level)
  YleTf::Logger::LEVELS.include?(level)
end

#log(progname, line) ⇒ Object



30
31
32
# File 'lib/yle_tf/system/output_logger.rb', line 30

def log(progname, line)
  YleTf::Logger.public_send(level, progname) { line }
end