LogAn::Inc::Fileparser::Line#event_line added and modified #event_read
This commit is contained in:
parent
b7d6689225
commit
7a244cd465
2 changed files with 23 additions and 23 deletions
|
@ -30,12 +30,14 @@ module LogAn
|
|||
@buffer, @linebuffer = Select::Buffer.new( ''), Select::Buffer.new( '')
|
||||
end
|
||||
|
||||
def event_read str, sock
|
||||
def event_read str, sock = nil
|
||||
@buffer += str
|
||||
@buffer.each! @delimiter do |line|
|
||||
emit line
|
||||
seeks line.length
|
||||
end
|
||||
@buffer.each! @delimiter, &method( :event_line)
|
||||
end
|
||||
|
||||
def event_line line
|
||||
emit line
|
||||
seeks line.length
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -45,15 +47,12 @@ module LogAn
|
|||
@multiline = multiline || /^\d\d-\d\d-\d\d:/
|
||||
end
|
||||
|
||||
def event_read str, sock
|
||||
@buffer += str
|
||||
@buffer.each! @delimiter do |line|
|
||||
if line =~ @multiline
|
||||
emit @linebuffer.to_s
|
||||
seeks @linebuffer.length
|
||||
@linebuffer.replace line
|
||||
else @linebuffer += line
|
||||
end
|
||||
def event_line line
|
||||
if line =~ @multiline
|
||||
emit @linebuffer.to_s
|
||||
seeks @linebuffer.length
|
||||
@linebuffer.replace line
|
||||
else @linebuffer += line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -51,9 +51,9 @@ module LogAn::Inc
|
|||
# : Server-Configuration. default { port: 1087 }
|
||||
def initialize conf
|
||||
super
|
||||
@conf = {}
|
||||
|
||||
# Copy config - changes possible
|
||||
@conf = {}
|
||||
conf.each {|key, val| @conf[key]= val }
|
||||
|
||||
# Default directories
|
||||
|
@ -90,13 +90,7 @@ module LogAn::Inc
|
|||
|
||||
# Select-framework
|
||||
@select = LogAn::Inc::Select.new
|
||||
status = lambda do
|
||||
@select.at Time.now+5, &status
|
||||
LogAn::Logging.info :recv_lines => @logs.counter,
|
||||
:connections => @serv && @serv.clients.map {|cl| cl.sock.peeraddr }
|
||||
@conf[:stores].each {|key, db| db.flush!}
|
||||
end
|
||||
status.call
|
||||
status # Init Status
|
||||
|
||||
# Prepare Inc-server - create server
|
||||
@serv = LogAn::Inc::Server.new :sock => TCPServer.new( *@conf[:server]),
|
||||
|
@ -112,6 +106,13 @@ module LogAn::Inc
|
|||
raise $!
|
||||
end
|
||||
|
||||
def status
|
||||
LogAn::Logging.info :recv_lines => @logs.counter,
|
||||
:connections => @serv && @serv.clients.map {|cl| cl.sock.peeraddr }
|
||||
@conf[ :stores].each {|key, db| db.flush!}
|
||||
@select.at Time.now+5, &status
|
||||
end
|
||||
|
||||
# Will be called at exit. Will close all opened BDB::Env
|
||||
def at_exit
|
||||
LogAn::Logging.info :at_exit
|
||||
|
@ -121,7 +122,7 @@ module LogAn::Inc
|
|||
|
||||
# Shutdown Server cleanly. First shutdown TCPServer.
|
||||
def shutdown signal = nil
|
||||
LogAn::Logging.info :signal, signal, Signal[signal] if signal
|
||||
LogAn::Logging.info :signal, signal, Signal[ signal] if signal
|
||||
@serv.close
|
||||
exit 0
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue