From dd1d1213473140760afd16e706ad06139563206b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Jun 2015 16:54:39 -0700 Subject: [PATCH] add log suffix in log filename Change-Id: I896a7fa07a292a83ff0b98e3b7a0014f1048698b --- compass/utils/logsetting.py | 11 +++++++---- compass/utils/setting_wrapper.py | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compass/utils/logsetting.py b/compass/utils/logsetting.py index 7c3cd3a1..c8d7615f 100644 --- a/compass/utils/logsetting.py +++ b/compass/utils/logsetting.py @@ -39,7 +39,8 @@ flags.add('log_interval_unit', help='log interval unit', default=setting.DEFAULT_LOGINTERVAL_UNIT) flags.add('log_format', help='log format', default=setting.DEFAULT_LOGFORMAT) - +flags.add('log_backup_count', type='int', + help='log backup count', default=setting.DEFAULT_LOGBACKUPCOUNT) # mapping str setting in flag --loglevel to logging level. LOGLEVEL_MAPPING = { @@ -71,12 +72,13 @@ def init(): if logdir: if not logfile: - logfile = os.path.basename(sys.argv[0]) + logfile = '%s.log' % os.path.basename(sys.argv[0]) handler = logging.handlers.TimedRotatingFileHandler( os.path.join(logdir, logfile), when=flags.OPTIONS.log_interval_unit, - interval=flags.OPTIONS.log_interval) + interval=flags.OPTIONS.log_interval, + backupCount=flags.OPTIONS.log_backup_count) else: if not logfile: handler = logging.StreamHandler(sys.stderr) @@ -84,7 +86,8 @@ def init(): handler = logging.handlers.TimedRotatingFileHandler( logfile, when=flags.OPTIONS.log_interval_unit, - interval=flags.OPTIONS.log_interval) + interval=flags.OPTIONS.log_interval, + backupCount=flags.OPTIONS.log_backup_count) if loglevel in LOGLEVEL_MAPPING: logger.setLevel(LOGLEVEL_MAPPING[loglevel]) diff --git a/compass/utils/setting_wrapper.py b/compass/utils/setting_wrapper.py index f478f394..f6a2ed55 100644 --- a/compass/utils/setting_wrapper.py +++ b/compass/utils/setting_wrapper.py @@ -41,6 +41,7 @@ DEFAULT_LOGINTERVAL = 1 DEFAULT_LOGINTERVAL_UNIT = 'h' DEFAULT_LOGFORMAT = ( '%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s') +DEFAULT_LOGBACKUPCOUNT = 5 WEB_LOGFILE = '' CELERY_LOGFILE = '' CELERYCONFIG_DIR = lazypy.delay(lambda: CONFIG_DIR)