From: Frank Brehm Date: Sun, 12 Dec 2010 14:11:47 +0000 (+0000) Subject: Bugfixing X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=78ee84808af0740783e79ce093cd40199d2ca1a6;p=my-stuff%2Fnagios.git Bugfixing git-svn-id: http://svn.brehm-online.com/svn/my-stuff/nagios/trunk@149 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/bin/fbrehm/common/logging_obj.py b/bin/fbrehm/common/logging_obj.py index b906453..95bf4d6 100755 --- a/bin/fbrehm/common/logging_obj.py +++ b/bin/fbrehm/common/logging_obj.py @@ -27,7 +27,7 @@ class LoggingObject(object): @param verbose: verbosity level (default: 0) @type verbose: int @param logger: a logger object for debugging a.s.o., will be created, if None - @type logger: a logging.getLogger object or None + @type logger: a logging.Logger object or None @return: None @rtype: None """ @@ -39,33 +39,34 @@ class LoggingObject(object): # Logging-Setup if logger is None: - self.init_logger() - else: + base_logger = self.init_base_logger() + self.logger = self.init_logger(base_logger) + elif isinstance( logger, logging.Logger ): + self.logger = self.init_logger( logger ) + elif isinstance( logger, logging.LoggerAdapter ): self.logger = logger - - if not ( isinstance( self.logger, logging.Logger ) or isinstance( self.logger, logging.LoggerAdapter ) ) : raise "self.logger is not a Logger or LoggerAdapter object" #------------------------------------------------------ - def init_logger( self, logger_name = 'base_logger' ): - """Initialize the logger property object, maybe overwritten. - In result the object must have a property 'logger' from type 'logging object' - @param logger_name: The name of the logging object - @type logger_name: str + def init_logger( self, logger ): + """Initializes a LoggerAdapter object and returns it. + @param logger: a logger object for debugging a.s.o., will be created, if None + @type logger: a logging.Logger object or None @return: None @rtype: None """ - self.__init_logger( logger_name ) + new_logger = logging.LoggerAdapter( logger, { 'class_name': self.__class__.__name__ } ) + + return new_logger #------------------------------------------------------ - def __init_logger( self, logger_name = 'base_logger' ): - """Initialize the logger property object, may NOT overwritten. - In result the object hast a property 'logger' from type 'logging object' + def init_base_logger( self, logger_name = 'base_logger' ): + """Initializes a logger object and returns it, maybe overwritten. @param logger_name: The name of the logging object @type logger_name: str - @return: None - @rtype: None + @return: logger object + @rtype: logging.Logger """ # Logging-Setup @@ -88,6 +89,8 @@ class LoggingObject(object): base_logger.addHandler(ch) - self.logger = logging.LoggerAdapter( base_logger, { 'class_name': self.__class__.__name__ } ) + return base_logger + +#------------------------------------------------------------------------------------------------- # vim: fileencoding=utf-8 filetype=python ts=4 expandtab diff --git a/bin/nagios/cfg/struct.py b/bin/nagios/cfg/struct.py index 94310b3..396ffc8 100755 --- a/bin/nagios/cfg/struct.py +++ b/bin/nagios/cfg/struct.py @@ -158,7 +158,7 @@ class NagiosConfigStruct(LoggingObject): key_upper = key.upper() return ( key_upper, value ) - verifier = NagiosObjectVerifier( logger = self.logger ) + verifier = NagiosObjectVerifier( logger = self.logger.logger ) res = None args = { 'file': file, 'row': rownum } check_type = None @@ -188,7 +188,7 @@ class NagiosConfigStruct(LoggingObject): args[argkey] = argval if 'deprecated' in args and args['deprecated']: - self.logger.warn( "Using of a deprecated {0} property {1!r} in {2!r}({3}).".format( + self.logger.warning( "Using of a deprecated {0} property {1!r} in {2!r}({3}).".format( object_type, key, file, rownum) ) if value is None: @@ -480,7 +480,7 @@ returns None on failure""" try: date_start = date( year, month, day ) except ValueError as e: - self.logger.warn( "Invalid date found in line {0!r}.".format( line ) ) + self.logger.warning( "Invalid date found in line {0!r}.".format( line ) ) return None key = date_start.isoformat() @@ -495,7 +495,7 @@ returns None on failure""" try: date_end = date( year, month, day ) except ValueError as e: - self.logger.warn( "Invalid date found in line {0!r}.".format( line ) ) + self.logger.warning( "Invalid date found in line {0!r}.".format( line ) ) return None key = key + ' - ' + date_end.isoformat() diff --git a/bin/nagios/config.py b/bin/nagios/config.py index effdb63..a807c91 100644 --- a/bin/nagios/config.py +++ b/bin/nagios/config.py @@ -108,7 +108,7 @@ class NagiosConfig(LoggingObject): def __del__( self ): "Destruktor" - self.logger.debug( "Hilfe - ich werde zerstört!!" ) + self.logger.debug( "Mayday - someone destroys me!!" ) #------------------------------------------------------ def canonize_file( self, f ): @@ -254,7 +254,7 @@ class NagiosConfig(LoggingObject): self.objects_read = {} files = set([]) dirs = set([]) - self.struct_verifier = NagiosConfigStruct( logger = self.base_logger, verbose = self.verbose ) + self.struct_verifier = NagiosConfigStruct( logger = self.logger.logger, verbose = self.verbose ) # cfg_file auswerten if 'cfg_file' in self.conf: @@ -367,7 +367,7 @@ class NagiosConfig(LoggingObject): else: # self.logger.debug( "Found: key: {0!r}, value: {1!r}".format( key, value ) ) if key in cur_object: - self.logger.warn( "Double entry of property {0!r} as {1!r} in {2}({3}).".format( + self.logger.warning( "Double entry of property {0!r} as {1!r} in {2}({3}).".format( key, object_type, file_name, row_num ) ) else: cur_object[key] = ( value, file_name, row_num )