From 38e251f02466f05c4b04f9e38698f8d506c07888 Mon Sep 17 00:00:00 2001 From: zbeacon Date: Thu, 23 Apr 2020 12:47:40 +0300 Subject: [PATCH] Improvements remote logging configuration processing --- setup.cfg | 16 ---------------- .../gateway/tb_gateway_remote_configurator.py | 10 ++++++++-- thingsboard_gateway/gateway/tb_logger.py | 2 +- 3 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 98393baf..00000000 --- a/setup.cfg +++ /dev/null @@ -1,16 +0,0 @@ -[metadata] -name = thingsboard-gateway -version = 2.2.5 -description = Thingsboard Gateway for IoT devices. -long_description= file: README.md -license = Apache Software License (Apache Software License 2.0) -url = https://github.com/thingsboard/thingsboard-gateway -author = ThingsBoard -author_email = info@thingsboard.io - -[options] -include_package_data = True -python_requires = >=3.5 - -[options.package_data] -* = config/* diff --git a/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py b/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py index 11811f05..440645d4 100644 --- a/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py +++ b/thingsboard_gateway/gateway/tb_gateway_remote_configurator.py @@ -13,10 +13,11 @@ # limitations under the License. from os import remove, linesep -from os.path import exists +from os.path import exists, dirname from re import findall from time import time, sleep from logging import getLogger +from logging.config import fileConfig from base64 import b64encode, b64decode from simplejson import dumps, loads, dump from yaml import safe_dump @@ -24,6 +25,7 @@ from configparser import ConfigParser from thingsboard_gateway.gateway.tb_client import TBClient from thingsboard_gateway.tb_utility.tb_utility import TBUtility +from thingsboard_gateway.gateway.tb_logger import TBLoggerHandler # pylint: disable=protected-access LOG = getLogger("service") @@ -262,10 +264,14 @@ class RemoteConfigurator: .split(', ')) path = args[0][1:-1] LOG.debug("Checking %s...", path) - if not exists(path): + if not exists(dirname(path)): raise FileNotFoundError with open(logs_conf_file_path, 'w', encoding="UTF-8") as logs: logs.write(self.__new_logs_configuration.replace("NONE", "NOTSET")+"\r\n") + fileConfig(logs_config) + LOG = getLogger('service') + # self.__gateway.remote_handler.deactivate() + self.__gateway.remote_handler = TBLoggerHandler(self.__gateway) self.__gateway.main_handler.setLevel(new_logging_level) self.__gateway.main_handler.setTarget(self.__gateway.remote_handler) if new_logging_level == "NOTSET": diff --git a/thingsboard_gateway/gateway/tb_logger.py b/thingsboard_gateway/gateway/tb_logger.py index 2b96e1f7..5545dd64 100644 --- a/thingsboard_gateway/gateway/tb_logger.py +++ b/thingsboard_gateway/gateway/tb_logger.py @@ -74,4 +74,4 @@ class TBLoggerHandler(logging.Handler): logger = logging.getLogger(logger_name) handler = logging.StreamHandler(stdout) handler.setFormatter(logging.Formatter('[STREAM ONLY] %(asctime)s - %(levelname)s - [%(filename)s] - %(module)s - %(lineno)d - %(message)s')) - logger.addHandler(handler) \ No newline at end of file + logger.addHandler(handler)