rm'd logging from exceptions; added logging in IS

The end result should the same, except now spawning multiple exeptions
wont cause duplicate log spam
This commit is contained in:
Rossen Georgiev 2014-12-30 20:24:12 +00:00
parent 7514c0ce55
commit 17acf41f33
2 changed files with 11 additions and 11 deletions

View File

@ -31,10 +31,15 @@ from .exceptions import (
ConnectionDrop, ConnectionDrop,
ConnectionError, ConnectionError,
LoginError, LoginError,
ParseError,
UnknownFormat,
) )
__all__ = ['IS'] __all__ = ['IS']
logging.addLevelName(11, "ParseError")
logging.addLevelName(9, "UnknownFormat")
class IS(object): class IS(object):
""" """
@ -150,6 +155,12 @@ class IS(object):
callback(self._parse(line)) callback(self._parse(line))
else: else:
self.logger.debug("Server: %s", line) self.logger.debug("Server: %s", line)
except ParseError as exp:
self.logger.log(11, "%s\n Packet: %s", exp.message, exp.packet)
except UnknownFormat as exp:
self.logger.log(9, "%s\n Packet: %s", exp.message, exp.packet)
except LoginError as exp:
self.logger.error("%s: %s", exp.__class__.__name__, exp.message)
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
raise raise
except (ConnectionDrop, ConnectionError): except (ConnectionDrop, ConnectionError):

View File

@ -18,7 +18,6 @@
""" """
Contains exception definitions for the module Contains exception definitions for the module
""" """
import logging
__all__ = [ __all__ = [
"GenericError", "GenericError",
@ -29,10 +28,6 @@ __all__ = [
"ConnectionDrop", "ConnectionDrop",
] ]
logging.raiseExceptions = False
logging.addLevelName(11, "ParseError")
logging.addLevelName(9, "UnknownFormat")
class GenericError(Exception): class GenericError(Exception):
""" """
@ -41,8 +36,6 @@ class GenericError(Exception):
def __init__(self, message): def __init__(self, message):
super(GenericError, self).__init__(message) super(GenericError, self).__init__(message)
self.logger = logging.getLogger(__name__)
class UnknownFormat(GenericError): class UnknownFormat(GenericError):
""" """
@ -53,7 +46,6 @@ class UnknownFormat(GenericError):
super(UnknownFormat, self).__init__(message) super(UnknownFormat, self).__init__(message)
self.packet = packet self.packet = packet
self.logger.log(9, "%s\n Packet: %s", message, packet)
class ParseError(GenericError): class ParseError(GenericError):
@ -64,7 +56,6 @@ class ParseError(GenericError):
super(ParseError, self).__init__(message) super(ParseError, self).__init__(message)
self.packet = packet self.packet = packet
self.logger.log(11, "%s\n Packet: %s", message, packet)
class LoginError(GenericError): class LoginError(GenericError):
@ -74,8 +65,6 @@ class LoginError(GenericError):
def __init__(self, message): def __init__(self, message):
super(LoginError, self).__init__(message) super(LoginError, self).__init__(message)
self.logger.error("%s: %s", self.__class__.__name__, message)
class ConnectionError(GenericError): class ConnectionError(GenericError):
""" """