From: laili Date: Mon, 6 Aug 2018 02:52:28 +0000 (+0800) Subject: Fix log error when run unit tests in windows X-Git-Tag: 1.2.0~140 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F61%2F59061%2F1;p=vfc%2Fnfvo%2Fcatalog.git Fix log error when run unit tests in windows Fix log error when run catalog tests in windows Change-Id: Ia075df00ba7b12529b1f81a2766b0a7c1b13f0c9 Issue-ID: VFC-1014 Signed-off-by: laili --- diff --git a/catalog/settings.py b/catalog/settings.py index 1920f1b2..67b58b92 100644 --- a/catalog/settings.py +++ b/catalog/settings.py @@ -14,6 +14,7 @@ import os import sys +import platform import redisco @@ -131,47 +132,44 @@ STATICFILES_DIRS = [ pub_config.CATALOG_ROOT_PATH = os.path.join(STATICFILES_DIRS[0], "catalog") pub_config.CATALOG_URL_PATH = "static/catalog" pub_config.SDC_BASE_URL = "http://%s:%s/api" % (pub_config.MSB_SERVICE_IP, pub_config.MSB_SERVICE_PORT) -# -# LOGGING = { -# 'version': 1, -# 'disable_existing_loggers': True, -# 'formatters': { -# 'standard': { -# 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s', -# }, -# }, -# 'filters': { -# }, -# 'handlers': { -# 'catalog_handler': { -# 'level': 'DEBUG', -# 'class': 'logging.handlers.RotatingFileHandler', -# 'filename': os.path.join(BASE_DIR, 'logs/runtime_catalog.log'), -# 'formatter': 'standard', -# 'maxBytes': 1024 * 1024 * 50, -# 'backupCount': 5, -# }, -# }, -# -# 'loggers': { -# 'catalog': { -# 'handlers': ['catalog_handler'], -# 'level': 'DEBUG', -# 'propagate': False -# }, -# } -# } - -LOGGING_CONFIG = None -# yaml configuration of logging -LOGGING_FILE = os.path.join(BASE_DIR, 'catalog/log.yml') -if 'test' in sys.argv: - os.system('sed -i "s|/var/log/onap/vfc/catalog|/tmp|" %s' % LOGGING_FILE) -log_config.yamlConfig(filepath=LOGGING_FILE, watchDog=True) -if 'test' in sys.argv: - os.system('sed -i "s|/tmp|/var/log/onap/vfc/catalog|" %s' % LOGGING_FILE) +if platform.system() == 'Windows' or 'test' in sys.argv: + LOGGING = { + 'version': 1, + 'disable_existing_loggers': True, + 'formatters': { + 'standard': { + 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s', + }, + }, + 'filters': { + }, + 'handlers': { + 'catalog_handler': { + 'level': 'DEBUG', + 'class': 'logging.handlers.RotatingFileHandler', + 'filename': os.path.join(BASE_DIR, 'logs/runtime_catalog.log'), + 'formatter': 'standard', + 'maxBytes': 1024 * 1024 * 50, + 'backupCount': 5, + }, + }, + 'loggers': { + 'catalog': { + 'handlers': ['catalog_handler'], + 'level': 'DEBUG', + 'propagate': False + }, + } + } +else: + LOGGING_CONFIG = None + # yaml configuration of logging + LOGGING_FILE = os.path.join(BASE_DIR, 'catalog/log.yml') + log_config.yamlConfig(filepath=LOGGING_FILE, watchDog=True) + +if 'test' in sys.argv: pub_config.REG_TO_MSB_WHEN_START = False DATABASES = {} @@ -181,7 +179,6 @@ if 'test' in sys.argv: } REST_FRAMEWORK = {} - import platform if platform.system() == 'Linux': TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner' TEST_OUTPUT_VERBOSE = True