import pwd
import grp
import glob
+import logging
from LogRotateCommon import split_parts, email_valid, period2days, human2bytes
from LogRotateScript import LogRotateScript
#-------------------------------------------------------
def __init__( self, config_file,
verbose = 0,
- logger = None,
local_dir = None,
test_mode = False,
):
@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.
@type: bool
'''
- self.logger = logger.getChild('config')
+ self.logger = logging.getLogger('pylogrotate.config')
'''
@ivar: logger object
@type: logging.getLogger
@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:
local_dir = self.local_dir,
verbose = self.verbose,
test_mode = self.test,
- logger = self.logger,
)
#------------------------------------------------------------
config_reader = LogrotateConfigurationReader(
config_file = self.config_file,
verbose = self.verbose,
- logger = self.logger,
local_dir = self.local_dir,
test_mode = self.test,
)
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):
local_dir = None,
verbose = 0,
test_mode = False,
- logger = None,
):
'''
Constructor.
@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.
@type: bool
'''
- self.logger = logger.getChild('status_file')
+ self.logger = logging.getLogger('pylogrotate.status_file')
'''
@ivar: logger object
@type: logging.getLogger
@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()