1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Improvements remote logging configuration processing

This commit is contained in:
zbeacon
2020-04-23 12:47:40 +03:00
parent 6d9adee8d8
commit 38e251f024
3 changed files with 9 additions and 19 deletions

View File

@@ -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":

View File

@@ -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)
logger.addHandler(handler)