From: Frank Brehm Date: Tue, 5 Jul 2011 11:45:11 +0000 (+0000) Subject: Logging korrigiert für Python 2.5 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=fcc801f67f04711615f4cbbfdf9015dd38240fcc;p=my-stuff%2Fpy-logrotate.git Logging korrigiert für Python 2.5 git-svn-id: http://svn.brehm-online.com/svn/my-stuff/python/PyLogrotate/trunk@279 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa --- diff --git a/LogRotateConfig.py b/LogRotateConfig.py index 5ede501..a9fd603 100755 --- a/LogRotateConfig.py +++ b/LogRotateConfig.py @@ -22,6 +22,7 @@ import os.path import pwd import grp import glob +import logging from LogRotateCommon import split_parts, email_valid, period2days, human2bytes from LogRotateScript import LogRotateScript @@ -156,7 +157,6 @@ class LogrotateConfigurationReader(object): #------------------------------------------------------- def __init__( self, config_file, verbose = 0, - logger = None, local_dir = None, test_mode = False, ): @@ -167,8 +167,6 @@ class LogrotateConfigurationReader(object): @type config_file: str @param verbose: verbosity (debug) level @type verbose: int - @param logger: logger object to use for logging a.s.o. - @type logger: logging.getLogger or None @param local_dir: The directory, where the i18n-files (*.mo) are located. If None, then system default (/usr/share/locale) is used. @@ -215,7 +213,7 @@ class LogrotateConfigurationReader(object): @type: bool ''' - self.logger = logger.getChild('config') + self.logger = logging.getLogger('pylogrotate.config') ''' @ivar: logger object @type: logging.getLogger @@ -227,34 +225,6 @@ class LogrotateConfigurationReader(object): @type: dict ''' - if not logger: - - ################################################# - # Create a logger object, if necessary - self.logger = logging.getLogger('logrotate_cfg') - - self.logger.setLevel(logging.DEBUG) - - pp = pprint.PrettyPrinter(indent=4) - # create console handler and set level to debug - ch = logging.StreamHandler() - #ch.setLevel(logging.DEBUG) - if verbose: - ch.setLevel(logging.DEBUG) - else: - ch.setLevel(logging.INFO) - - # create formatter - formatter = logging.Formatter( - '[%(asctime)s]: %(name)s %(levelname)-8s - %(message)s' - ) - - # add formatter to ch - ch.setFormatter(formatter) - - # add ch to logger - self.logger.addHandler(ch) - ############################################# # the rest of instance variables: diff --git a/LogRotateHandler.py b/LogRotateHandler.py index a82af36..7a7e4a4 100755 --- a/LogRotateHandler.py +++ b/LogRotateHandler.py @@ -316,7 +316,6 @@ class LogrotateHandler(object): local_dir = self.local_dir, verbose = self.verbose, test_mode = self.test, - logger = self.logger, ) #------------------------------------------------------------ @@ -427,7 +426,6 @@ class LogrotateHandler(object): config_reader = LogrotateConfigurationReader( config_file = self.config_file, verbose = self.verbose, - logger = self.logger, local_dir = self.local_dir, test_mode = self.test, ) diff --git a/LogRotateScript.py b/LogRotateScript.py index e4637ff..34268ca 100755 --- a/LogRotateScript.py +++ b/LogRotateScript.py @@ -180,15 +180,6 @@ class LogRotateScript(object): name = property(_get_name, None, None, "Name of the script as an identifier") - #@property - #def name(self): - # ''' - # Property 'name' as the name of the script as an identifier - # - # readonly - # ''' - # return self._name - #------------------------------------------------------------ # Property 'cmd' def _get_cmd(self): diff --git a/LogRotateStatusFile.py b/LogRotateStatusFile.py index 782a9a4..5dc4b3c 100755 --- a/LogRotateStatusFile.py +++ b/LogRotateStatusFile.py @@ -77,7 +77,6 @@ class LogrotateStatusFile(object): local_dir = None, verbose = 0, test_mode = False, - logger = None, ): ''' Constructor. @@ -88,8 +87,6 @@ class LogrotateStatusFile(object): @type verbose: int @param test_mode: test mode - no write actions are made @type test_mode: bool - @param logger: logger object to use for logging a.s.o. - @type logger: logging.getLogger or None @param local_dir: The directory, where the i18n-files (*.mo) are located. If None, then system default (/usr/share/locale) is used. @@ -164,7 +161,7 @@ class LogrotateStatusFile(object): @type: bool ''' - self.logger = logger.getChild('status_file') + self.logger = logging.getLogger('pylogrotate.status_file') ''' @ivar: logger object @type: logging.getLogger @@ -180,34 +177,6 @@ class LogrotateStatusFile(object): @type: dict ''' - if not logger: - - ################################################# - # Create a logger object, if necessary - self.logger = logging.getLogger('logrotate_state_file') - - self.logger.setLevel(logging.DEBUG) - - pp = pprint.PrettyPrinter(indent=4) - # create console handler and set level to debug - ch = logging.StreamHandler() - #ch.setLevel(logging.DEBUG) - if verbose: - ch.setLevel(logging.DEBUG) - else: - ch.setLevel(logging.INFO) - - # create formatter - formatter = logging.Formatter( - '[%(asctime)s]: %(name)s %(levelname)-8s - %(message)s' - ) - - # add formatter to ch - ch.setFormatter(formatter) - - # add ch to logger - self.logger.addHandler(ch) - # Initial read and check for permissions self.read(must_exists = False) self._check_permissions()