add log suffix in log filename

Change-Id: I896a7fa07a292a83ff0b98e3b7a0014f1048698b
This commit is contained in:
root 2015-06-03 16:54:39 -07:00 committed by xiaodong.wang
parent f3de83c213
commit dd1d121347
2 changed files with 8 additions and 4 deletions

View File

@ -39,7 +39,8 @@ flags.add('log_interval_unit',
help='log interval unit', default=setting.DEFAULT_LOGINTERVAL_UNIT) help='log interval unit', default=setting.DEFAULT_LOGINTERVAL_UNIT)
flags.add('log_format', flags.add('log_format',
help='log format', default=setting.DEFAULT_LOGFORMAT) 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. # mapping str setting in flag --loglevel to logging level.
LOGLEVEL_MAPPING = { LOGLEVEL_MAPPING = {
@ -71,12 +72,13 @@ def init():
if logdir: if logdir:
if not logfile: if not logfile:
logfile = os.path.basename(sys.argv[0]) logfile = '%s.log' % os.path.basename(sys.argv[0])
handler = logging.handlers.TimedRotatingFileHandler( handler = logging.handlers.TimedRotatingFileHandler(
os.path.join(logdir, logfile), os.path.join(logdir, logfile),
when=flags.OPTIONS.log_interval_unit, when=flags.OPTIONS.log_interval_unit,
interval=flags.OPTIONS.log_interval) interval=flags.OPTIONS.log_interval,
backupCount=flags.OPTIONS.log_backup_count)
else: else:
if not logfile: if not logfile:
handler = logging.StreamHandler(sys.stderr) handler = logging.StreamHandler(sys.stderr)
@ -84,7 +86,8 @@ def init():
handler = logging.handlers.TimedRotatingFileHandler( handler = logging.handlers.TimedRotatingFileHandler(
logfile, logfile,
when=flags.OPTIONS.log_interval_unit, 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: if loglevel in LOGLEVEL_MAPPING:
logger.setLevel(LOGLEVEL_MAPPING[loglevel]) logger.setLevel(LOGLEVEL_MAPPING[loglevel])

View File

@ -41,6 +41,7 @@ DEFAULT_LOGINTERVAL = 1
DEFAULT_LOGINTERVAL_UNIT = 'h' DEFAULT_LOGINTERVAL_UNIT = 'h'
DEFAULT_LOGFORMAT = ( DEFAULT_LOGFORMAT = (
'%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s') '%(asctime)s - %(filename)s - %(lineno)d - %(levelname)s - %(message)s')
DEFAULT_LOGBACKUPCOUNT = 5
WEB_LOGFILE = '' WEB_LOGFILE = ''
CELERY_LOGFILE = '' CELERY_LOGFILE = ''
CELERYCONFIG_DIR = lazypy.delay(lambda: CONFIG_DIR) CELERYCONFIG_DIR = lazypy.delay(lambda: CONFIG_DIR)