@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
"""
# 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
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
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
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:
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()
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()
def __del__( self ):
"Destruktor"
- self.logger.debug( "Hilfe - ich werde zerstört!!" )
+ self.logger.debug( "Mayday - someone destroys me!!" )
#------------------------------------------------------
def canonize_file( self, f ):
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:
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 )