From 17acf41f33be0aa254ad816a7afd15fd4f77712c Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Tue, 30 Dec 2014 20:24:12 +0000 Subject: [PATCH] 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 --- aprslib/IS.py | 11 +++++++++++ aprslib/exceptions.py | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/aprslib/IS.py b/aprslib/IS.py index 14d74c9..fc0d16b 100644 --- a/aprslib/IS.py +++ b/aprslib/IS.py @@ -31,10 +31,15 @@ from .exceptions import ( ConnectionDrop, ConnectionError, LoginError, + ParseError, + UnknownFormat, ) __all__ = ['IS'] +logging.addLevelName(11, "ParseError") +logging.addLevelName(9, "UnknownFormat") + class IS(object): """ @@ -150,6 +155,12 @@ class IS(object): callback(self._parse(line)) else: 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): raise except (ConnectionDrop, ConnectionError): diff --git a/aprslib/exceptions.py b/aprslib/exceptions.py index e3dd3d9..536a9c1 100644 --- a/aprslib/exceptions.py +++ b/aprslib/exceptions.py @@ -18,7 +18,6 @@ """ Contains exception definitions for the module """ -import logging __all__ = [ "GenericError", @@ -29,10 +28,6 @@ __all__ = [ "ConnectionDrop", ] -logging.raiseExceptions = False -logging.addLevelName(11, "ParseError") -logging.addLevelName(9, "UnknownFormat") - class GenericError(Exception): """ @@ -41,8 +36,6 @@ class GenericError(Exception): def __init__(self, message): super(GenericError, self).__init__(message) - self.logger = logging.getLogger(__name__) - class UnknownFormat(GenericError): """ @@ -53,7 +46,6 @@ class UnknownFormat(GenericError): super(UnknownFormat, self).__init__(message) self.packet = packet - self.logger.log(9, "%s\n Packet: %s", message, packet) class ParseError(GenericError): @@ -64,7 +56,6 @@ class ParseError(GenericError): super(ParseError, self).__init__(message) self.packet = packet - self.logger.log(11, "%s\n Packet: %s", message, packet) class LoginError(GenericError): @@ -74,8 +65,6 @@ class LoginError(GenericError): def __init__(self, message): super(LoginError, self).__init__(message) - self.logger.error("%s: %s", self.__class__.__name__, message) - class ConnectionError(GenericError): """