LogAn::Logging for logging added.
This commit is contained in:
parent
a314bd8d9a
commit
adbf24bcdc
1 changed files with 13 additions and 6 deletions
|
@ -7,6 +7,13 @@ require 'logan/inc'
|
||||||
require 'logan/loglines'
|
require 'logan/loglines'
|
||||||
require 'logan/cache'
|
require 'logan/cache'
|
||||||
|
|
||||||
|
module LogAn::Logging
|
||||||
|
def log lvl, *txt
|
||||||
|
$stderr.puts( ([Time.now, lvl]+txt).inspect)
|
||||||
|
end
|
||||||
|
alias method_missing log
|
||||||
|
end
|
||||||
|
|
||||||
module LogAn::Inc
|
module LogAn::Inc
|
||||||
class Main < RobustServer
|
class Main < RobustServer
|
||||||
def cache ret, type, &e
|
def cache ret, type, &e
|
||||||
|
@ -18,13 +25,13 @@ module LogAn::Inc
|
||||||
|
|
||||||
# Open Store.
|
# Open Store.
|
||||||
def store env, db, type = nil, flags = nil, &e
|
def store env, db, type = nil, flags = nil, &e
|
||||||
$stderr.puts [:store, :open, "sids.cnf", db, type].inspect
|
LogAn::Logging.info :store, :open, "sids.cnf", db, type
|
||||||
cache env[ 'sids.cnf', db, :flags => flags || SBDB::CREATE | SBDB::AUTO_COMMIT], type, &e
|
cache env[ 'sids.cnf', db, :flags => flags || SBDB::CREATE | SBDB::AUTO_COMMIT], type, &e
|
||||||
end
|
end
|
||||||
|
|
||||||
# Open Config.
|
# Open Config.
|
||||||
def config env, db, type = nil, flags = nil, &e
|
def config env, db, type = nil, flags = nil, &e
|
||||||
$stderr.puts [:config, :open, "sids.cnf", db, type].inspect
|
LogAn::Logging.info :config, :open, "sids.cnf", db, type
|
||||||
cache env[ 'sids.cnf', db, :flags => flags || SBDB::RDONLY], type, &e
|
cache env[ 'sids.cnf', db, :flags => flags || SBDB::RDONLY], type, &e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -78,14 +85,14 @@ module LogAn::Inc
|
||||||
@select = LogAn::Inc::Select.new
|
@select = LogAn::Inc::Select.new
|
||||||
status = lambda do
|
status = lambda do
|
||||||
@select.at Time.now+5, &status
|
@select.at Time.now+5, &status
|
||||||
$stderr.puts "#{Time.now.strftime"%H:%M:%S"}|INFO|Statistic|#{@select.inspect}"
|
LogAn::Logging.info @select
|
||||||
@conf[:stores].each{|key, db| db.flush!}
|
@conf[:stores].each{|key, db| db.flush!}
|
||||||
end
|
end
|
||||||
status.call
|
status.call
|
||||||
|
|
||||||
# Prepare Inc-server - create server
|
# Prepare Inc-server - create server
|
||||||
@serv = LogAn::Inc::Server.new :sock => TCPServer.new( *@conf[:server]), :config => @conf[:configs], :select => @select
|
@serv = LogAn::Inc::Server.new :sock => TCPServer.new( *@conf[:server]), :config => @conf[:configs], :select => @select
|
||||||
$stderr.puts @serv.inspect
|
LogAn::Logging.debug @serv
|
||||||
|
|
||||||
# Shutdown on signals
|
# Shutdown on signals
|
||||||
@sigs[:INT] = @sigs[:TERM] = method( :shutdown)
|
@sigs[:INT] = @sigs[:TERM] = method( :shutdown)
|
||||||
|
@ -98,14 +105,14 @@ module LogAn::Inc
|
||||||
|
|
||||||
# Will be called at exit. Will close all opened BDB::Env
|
# Will be called at exit. Will close all opened BDB::Env
|
||||||
def at_exit
|
def at_exit
|
||||||
$stderr.puts :at_exit
|
LogAn::Logging.info :at_exit
|
||||||
@logs and @logs.close
|
@logs and @logs.close
|
||||||
@etc and @etc.close
|
@etc and @etc.close
|
||||||
end
|
end
|
||||||
|
|
||||||
# Shutdown Server cleanly. First shutdown TCPServer.
|
# Shutdown Server cleanly. First shutdown TCPServer.
|
||||||
def shutdown signal = nil
|
def shutdown signal = nil
|
||||||
$stderr.puts [:signal, signal, Signal[signal]].inspect if signal
|
LogAn::Logging.info :signal, signal, Signal[signal]] if signal
|
||||||
@serv.close
|
@serv.close
|
||||||
exit 0
|
exit 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue