aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils
diff options
context:
space:
mode:
authorhelenyao <yaohelan@huawei.com>2017-02-10 03:52:58 -0500
committerhelenyao <yaohelan@huawei.com>2017-02-10 04:05:41 -0500
commit93a64634f99a64009fe762fb69e774e3524cc9be (patch)
treeb4d8dd474e566cfc08a2ed6517a310a165076229 /functest/utils
parent7ddaeed03b3360ec1041a50836bbd063a1533aed (diff)
Put the Logger as Object oriented.
There is no need to worry about adding duplicate handler as the logging has the ability to avoid it. Change-Id: I7198c1e1c05df347feb0d7192e80592e662314b1 Signed-off-by: helenyao <yaohelan@huawei.com>
Diffstat (limited to 'functest/utils')
-rwxr-xr-xfunctest/utils/functest_logger.py58
1 files changed, 26 insertions, 32 deletions
diff --git a/functest/utils/functest_logger.py b/functest/utils/functest_logger.py
index f09f56be0..0cba8c528 100755
--- a/functest/utils/functest_logger.py
+++ b/functest/utils/functest_logger.py
@@ -28,42 +28,36 @@ import json
from functest.utils.constants import CONST
-logger = logging.getLogger(__name__)
-
-
-def is_debug():
- if CONST.CI_DEBUG and CONST.CI_DEBUG.lower() == "true":
- return True
- return False
-
-
-def setup_logging(default_path=CONST.dir_functest_logging_cfg,
- default_level=logging.INFO,
- env_key='LOG_CFG'):
- path = default_path
- value = os.getenv(env_key, None)
- if value:
- path = value
- if os.path.exists(path):
- with open(path, 'rt') as f:
- config = json.load(f)
- if (config['handlers'] and
- config['handlers']['console']):
- stream_level = logging.INFO
- if is_debug():
- stream_level = logging.DEBUG
- config['handlers']['console']['level'] = stream_level
- logging.config.dictConfig(config)
- else:
- logging.basicConfig(level=default_level)
-
-
-setup_logging()
-
class Logger:
def __init__(self, logger_name):
+ self.setup_logging()
self.logger = logging.getLogger(logger_name)
def getLogger(self):
return self.logger
+
+ def is_debug(self):
+ if CONST.CI_DEBUG and CONST.CI_DEBUG.lower() == "true":
+ return True
+ return False
+
+ def setup_logging(self, default_path=CONST.dir_functest_logging_cfg,
+ default_level=logging.INFO,
+ env_key='LOG_CFG'):
+ path = default_path
+ value = os.getenv(env_key, None)
+ if value:
+ path = value
+ if os.path.exists(path):
+ with open(path, 'rt') as f:
+ config = json.load(f)
+ if (config['handlers'] and
+ config['handlers']['console']):
+ stream_level = logging.INFO
+ if self.is_debug():
+ stream_level = logging.DEBUG
+ config['handlers']['console']['level'] = stream_level
+ logging.config.dictConfig(config)
+ else:
+ logging.basicConfig(level=default_level)