Author: remi
Date: 2008-12-13 16:27:10 +0100 (Sat, 13 Dec 2008)
New Revision: 3081
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
Log:
* added a logger in the IPN server.
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
2008-12-13 14:32:15 UTC (rev 3080)
+++
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/IPN/IPNServer.py
2008-12-13 15:27:10 UTC (rev 3081)
@@ -21,6 +21,8 @@
except:
from md5 import md5
+from tuxisalive.lib.logger import *
+
# Formated PING command
_PING_CMD = "PING\n" + "".join(" " * 123)
@@ -59,6 +61,11 @@
self.__runPingMutex = threading.Lock()
self.__onClientAdded = None
self.__onClientRemoved = None
+ self.__logger = SimpleLogger("IPNServer_%s" % str(self.__port))
+ self.__logger.setTarget(LOG_TARGET_FILE)
+ self.__logger.setLevel(LOG_LEVEL_INFO)
+ self.__logger.resetLog()
+ self.__logger.logInfo("Created")
#
--------------------------------------------------------------------------
# Register a callback function to the "On client added" event.
@@ -125,18 +132,26 @@
self.__runPingThread.start()
time.sleep(0.1)
# Server successfuly started
+ self.__logger.logInfo("Server successfully started (%s:%d)" % (
+ self.__host, self.__port))
return True
except socket.timeout:
self.__setRunLst(False)
# Failed to start the server
+ self.__logger.logError("Failed to start the server (%s:%d) : %s" %
(
+ self.__host, self.__port, "Socket.timeout"))
return False
except socket.error:
self.__setRunLst(False)
# Failed to start the server
+ self.__logger.logError("Failed to start the server (%s:%d) : %s" %
(
+ self.__host, self.__port, "Socket.error"))
return False
except:
self.__setRunLst(False)
# Failed to start the server
+ self.__logger.logError("Failed to start the server (%s:%d) : %s" %
(
+ self.__host, self.__port, "Unexpected error"))
return False
#
--------------------------------------------------------------------------
@@ -162,6 +177,7 @@
self.__runPingThread.join()
# Clear the clients list
self.__clearClients()
+ self.__logger.logInfo("Server successfully stopped")
#
--------------------------------------------------------------------------
# Wait that the server has stopped.
@@ -174,6 +190,15 @@
time.sleep(0.5)
#
--------------------------------------------------------------------------
+ # Get the log file path.
+ #
--------------------------------------------------------------------------
+ def getLogFilePath(self):
+ """Get the log file path.
+ @return: The log file path.
+ """
+ return self.__logger.getLogFilePath()
+
+ #
--------------------------------------------------------------------------
# Get the state of the listening loop.
#
--------------------------------------------------------------------------
def __getRunLst(self):
@@ -252,6 +277,7 @@
# Call the "On client added" event
if self.__onClientAdded != None:
self.__onClientAdded(id)
+ self.__logger.logInfo("New client added (%s)" % id)
#
--------------------------------------------------------------------------
# Remove a client from the clients list.
@@ -274,6 +300,7 @@
if removedId != None:
if self.__onClientRemoved != None:
self.__onClientRemoved(removedId)
+ self.__logger.logInfo("Client removed (%s)" % removedId)
#
--------------------------------------------------------------------------
# Clear the clients list.
@@ -324,6 +351,8 @@
self.__cliMutex.release()
# If an error occuring during the client ping then remove
it
# from the clients list
+ self.__logger.logInfo("Client socket error (%s)" % \
+ cli['id'])
self.__removeClient(cli['address'])
aClientHasRemoved = True
self.__cliMutex.acquire()
@@ -332,6 +361,8 @@
self.__cliMutex.release()
# If the client response is invalid then remove it from the
# clients list
+ self.__logger.logInfo("Client not responding (%s)" % \
+ cli['id'])
self.__removeClient(cli['address'])
aClientHasRemoved = True
self.__cliMutex.acquire()
@@ -356,6 +387,7 @@
if len(message) == 0:
message = "NOTIFY"
message = message + "\n" + "".join(" " * (127 - len(message)))
+ self.__logger.logDebug("Notified : (%s)" % message)
self.__cliMutex.acquire()
# Send the message to all registered clients
for cli in self.__cliLst:
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn