2018-01-03 18:53:34 +00:00
|
|
|
import json
|
|
|
|
import logging.config
|
|
|
|
import os
|
2018-03-03 00:22:20 +00:00
|
|
|
import subprocess
|
2013-08-29 15:21:13 +01:00
|
|
|
|
2018-01-03 18:53:34 +00:00
|
|
|
from core import constants
|
2013-08-29 15:21:13 +01:00
|
|
|
|
2019-02-16 17:50:19 +00:00
|
|
|
# setup default null handler
|
|
|
|
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
2018-01-03 18:53:34 +00:00
|
|
|
|
2019-02-16 17:50:19 +00:00
|
|
|
|
2019-09-10 21:39:36 +01:00
|
|
|
def load_logging_config(config_path=None):
|
2019-02-16 17:50:19 +00:00
|
|
|
"""
|
|
|
|
Load CORE logging configuration file.
|
|
|
|
|
2019-09-10 21:39:36 +01:00
|
|
|
:param str config_path: path to logging config file,
|
|
|
|
when None defaults to /etc/core/logging.conf
|
2019-02-16 17:50:19 +00:00
|
|
|
:return: nothing
|
|
|
|
"""
|
2019-09-10 21:39:36 +01:00
|
|
|
if config_path is None:
|
|
|
|
config_path = os.path.join(constants.CORE_CONF_DIR, "logging.conf")
|
|
|
|
with open(config_path, "r") as log_config_file:
|
2019-02-16 17:50:19 +00:00
|
|
|
log_config = json.load(log_config_file)
|
|
|
|
logging.config.dictConfig(log_config)
|
2018-01-03 22:40:45 +00:00
|
|
|
|
2018-03-03 00:22:20 +00:00
|
|
|
|
|
|
|
class CoreCommandError(subprocess.CalledProcessError):
|
|
|
|
"""
|
|
|
|
Used when encountering internal CORE command errors.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Command(%s), Status(%s):\n%s" % (self.cmd, self.returncode, self.output)
|