Class: ModSpox::LogWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/mod_spox/Logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fd) ⇒ LogWriter

Returns a new instance of LogWriter.



50
51
52
53
54
55
56
57
58
59
# File 'lib/mod_spox/Logger.rb', line 50

def initialize(fd)
    @fd = fd
    @kill = false
    @queue = Queue.new
    @thread = Thread.new do
        until(@kill)
            processor
        end
    end
end

Instance Attribute Details

#fdObject (readonly)

Returns the value of attribute fd.



48
49
50
# File 'lib/mod_spox/Logger.rb', line 48

def fd
  @fd
end

Instance Method Details

#killObject



61
62
63
64
# File 'lib/mod_spox/Logger.rb', line 61

def kill
    @kill = true
    @queue << "Logger has been told to shut down"
end

#log(message) ⇒ Object



66
67
68
# File 'lib/mod_spox/Logger.rb', line 66

def log(message)
    @queue << message
end

#processorObject



70
71
72
73
# File 'lib/mod_spox/Logger.rb', line 70

def processor
    message = @queue.pop
    @fd.puts("LOGGER [#{Time.now}]: #{message}")
end