Changes for logging.

This commit is contained in:
Eratosthenes 2009-11-23 19:34:40 -05:00
parent bdc3248597
commit ad91c0a526

View File

@ -36,9 +36,7 @@ import traceback
(options, sys.argv) = Options.fpdb_options() (options, sys.argv) = Options.fpdb_options()
if not options.errorsToConsole: if not options.errorsToConsole:
print "Note: error output is being diverted to fpdb-error-log.txt and HUD-error.txt. Any major error will be reported there _only_." print "Note: error output is being logged. Any major error will be reported there _only_."
errorFile = open('HUD-error.txt', 'w', 0)
sys.stderr = errorFile
import thread import thread
import time import time
@ -52,6 +50,13 @@ import gobject
# FreePokerTools modules # FreePokerTools modules
import Configuration import Configuration
print "start logging"
log = Configuration.get_logger("logging.conf", config = 'hud')
log.debug("%s logger initialized." % "dud")
print "logging started"
import Database import Database
from HandHistoryConverter import getTableTitleRe from HandHistoryConverter import getTableTitleRe
# get the correct module for the current os # get the correct module for the current os
@ -97,6 +102,7 @@ class HUD_main(object):
def __init__(self, db_name = 'fpdb'): def __init__(self, db_name = 'fpdb'):
self.db_name = db_name self.db_name = db_name
self.log = log
self.config = Configuration.Config(file=options.config, dbname=options.dbname) self.config = Configuration.Config(file=options.config, dbname=options.dbname)
self.hud_dict = {} self.hud_dict = {}
self.hud_params = self.config.get_hud_ui_parameters() self.hud_params = self.config.get_hud_ui_parameters()
@ -116,6 +122,7 @@ class HUD_main(object):
self.main_window.show_all() self.main_window.show_all()
def destroy(self, *args): # call back for terminating the main eventloop def destroy(self, *args): # call back for terminating the main eventloop
self.log.info("Terminating normally.")
gtk.main_quit() gtk.main_quit()
def kill_hud(self, event, table): def kill_hud(self, event, table):
@ -180,10 +187,10 @@ class HUD_main(object):
# function idle_func() to be run by the gui thread, at its leisure. # function idle_func() to be run by the gui thread, at its leisure.
def idle_func(): def idle_func():
gtk.gdk.threads_enter() gtk.gdk.threads_enter()
# try: try:
self.hud_dict[table_name].update(new_hand_id, config) self.hud_dict[table_name].update(new_hand_id, config)
[aw.update_gui(new_hand_id) for aw in self.hud_dict[table_name].aux_windows] [aw.update_gui(new_hand_id) for aw in self.hud_dict[table_name].aux_windows]
# finally: finally:
gtk.gdk.threads_leave() gtk.gdk.threads_leave()
return False return False
@ -197,7 +204,6 @@ class HUD_main(object):
# need their own access to the database, but should open their own # need their own access to the database, but should open their own
# if it is required. # if it is required.
self.db_connection = Database.Database(self.config) self.db_connection = Database.Database(self.config)
# get hero's screen names and player ids # get hero's screen names and player ids
self.hero, self.hero_ids = {}, {} self.hero, self.hero_ids = {}, {}
for site in self.config.get_supported_sites(): for site in self.config.get_supported_sites():
@ -210,6 +216,7 @@ class HUD_main(object):
while 1: # wait for a new hand number on stdin while 1: # wait for a new hand number on stdin
new_hand_id = sys.stdin.readline() new_hand_id = sys.stdin.readline()
new_hand_id = string.rstrip(new_hand_id) new_hand_id = string.rstrip(new_hand_id)
self.log.debug("Received hand no %s" % new_hand_id)
if new_hand_id == "": # blank line means quit if new_hand_id == "": # blank line means quit
self.destroy() self.destroy()
break # this thread is not always killed immediately with gtk.main_quit() break # this thread is not always killed immediately with gtk.main_quit()
@ -220,8 +227,7 @@ class HUD_main(object):
(table_name, max, poker_game, type, site_id, site_name, tour_number, tab_number) = \ (table_name, max, poker_game, type, site_id, site_name, tour_number, tab_number) = \
self.db_connection.get_table_info(new_hand_id) self.db_connection.get_table_info(new_hand_id)
except Exception, err: except Exception, err:
print "db error: skipping %s" % new_hand_id self.log.error("db error: skipping %s" % new_hand_id)
sys.stderr.write("Database error: could not find hand %s.\n" % new_hand_id)
continue continue
if type == "tour": # hand is from a tournament if type == "tour": # hand is from a tournament
@ -262,7 +268,8 @@ class HUD_main(object):
# If no client window is found on the screen, complain and continue # If no client window is found on the screen, complain and continue
if type == "tour": if type == "tour":
table_name = "%s %s" % (tour_number, tab_number) table_name = "%s %s" % (tour_number, tab_number)
sys.stderr.write("HUD create: table name "+table_name+" not found, skipping.\n") # sys.stderr.write("HUD create: table name "+table_name+" not found, skipping.\n")
self.log.error("HUD create: table name %s not found, skipping." % table_name)
else: else:
tablewindow.max = max tablewindow.max = max
tablewindow.site = site_name tablewindow.site = site_name
@ -271,8 +278,8 @@ class HUD_main(object):
if __name__== "__main__": if __name__== "__main__":
sys.stderr.write("HUD_main starting\n") log.info("HUD_main starting")
sys.stderr.write("Using db name = %s\n" % (options.dbname)) log.info("Using db name = %s" % (options.dbname))
# start the HUD_main object # start the HUD_main object
hm = HUD_main(db_name = options.dbname) hm = HUD_main(db_name = options.dbname)