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

Fix for log handlers

This commit is contained in:
imbeacon
2023-12-06 15:41:36 +02:00
parent bb8fe9d04e
commit e26ba45a2e
4 changed files with 23 additions and 12 deletions

View File

@@ -35,12 +35,10 @@ sudo cp -a -r /etc/thingsboard-gateway/extensions /var/lib/thingsboard_gateway/
sudo rm -r /etc/thingsboard-gateway/extensions
sudo usermod -a -G dialout $CURRENT_USER
sudo usermod -a -G thingsboard_gateway $CURRENT_USER
sudo touch /tmp/gateway
sudo chown thingsboard_gateway:thingsboard_gateway /tmp/gateway
sudo chown thingsboard_gateway:thingsboard_gateway /var/log/thingsboard-gateway/ -R
sudo chown thingsboard_gateway:thingsboard_gateway /var/lib/thingsboard_gateway/ -R
sudo chown thingsboard_gateway:thingsboard_gateway /etc/thingsboard-gateway/ -R
sudo sed -i 's/\.\/logs/\/var\/log\/thingsboard-gateway/g' /etc/thingsboard-gateway/config/logs.conf >> /etc/thingsboard-gateway/config/logs.conf
sudo sed -i 's/\.\/logs/\/var\/log\/thingsboard-gateway/g' /etc/thingsboard-gateway/config/logs.json >> /etc/thingsboard-gateway/config/logs.json
echo "Installation completed"
echo "Enabling daemon..."
sudo pidof systemd && sudo systemctl enable thingsboard-gateway || echo "Systemctl not found, cannot enable the daemon!"

View File

@@ -59,7 +59,7 @@ try:
except ImportError:
print("Cannot load GRPC connector!")
log = None
log:TbLogger = None
main_handler = logging.handlers.MemoryHandler(-1)
DEFAULT_CONNECTORS = {
@@ -515,6 +515,8 @@ class TBGatewayService:
if self.__grpc_manager is not None:
self.__grpc_manager.stop()
if os.path.exists("/tmp/gateway"):
os.remove("/tmp/gateway")
self.__close_connectors()
self._event_storage.stop()
log.info("The gateway has been stopped.")

View File

@@ -20,9 +20,10 @@ from typing import Union
import simplejson
from simplejson import dumps
from thingsboard_gateway.gateway.proto.messages_pb2 import *
from thingsboard_gateway.grpc_connectors.gw_grpc_client import GrpcClient
from thingsboard_gateway.grpc_connectors.gw_grpc_msg_creator import GrpcMsgCreator, Status
from thingsboard_gateway.gateway.proto.messages_pb2 import *
log = getLogger('connector')
@@ -30,7 +31,7 @@ log = getLogger('connector')
class GwGrpcConnector(Thread):
def __init__(self, connector_config: str, config_dir_path: str):
super().__init__()
fileConfig(config_dir_path + 'logs.conf')
fileConfig(config_dir_path + 'logs.json')
global log
log = getLogger('connector')
self.stopped = False

View File

@@ -14,12 +14,12 @@
import os.path
from logging import getLogger
from time import sleep, time
from logging.config import dictConfig
from time import sleep, time
from packaging import version
from regex import fullmatch
from simplejson import dumps, load
from packaging import version
from thingsboard_gateway.gateway.tb_client import TBClient
from thingsboard_gateway.tb_utility.tb_handler import TBLoggerHandler
@@ -231,8 +231,8 @@ class RemoteConfigurator:
try:
with open(self._gateway.get_config_path() + 'logs.json', 'r') as logs:
return load(logs)
except Exception as e:
LOG.exception(e)
except Exception:
LOG.warning("Cannot open logs configuration file. Using default logs configuration.")
return {}
def process_config_request(self, config):
@@ -383,7 +383,17 @@ class RemoteConfigurator:
try:
LOG = getLogger('service')
logs_conf_file_path = self._gateway.get_config_path() + 'logs.json'
target_handlers = {}
for handler in config['handlers']:
filename = config['handlers'][handler].get('filename')
if "consoleHandler" == handler or (filename is not None and os.path.exists(filename)):
target_handlers[handler] = config['handlers'][handler]
else:
LOG.warning('Handler %s not found. Removing from configuration...', handler)
for logger in config['loggers']:
if handler in config['loggers'][logger]['handlers']:
config['loggers'][logger]['handlers'].remove(handler)
config['handlers'] = target_handlers
dictConfig(config)
LOG = getLogger('service')
self._gateway.remote_handler = TBLoggerHandler(self._gateway)
@@ -397,7 +407,7 @@ class RemoteConfigurator:
LOG.debug("Logs configuration has been updated.")
self._gateway.tb_client.client.send_attributes({'logs_configuration': config})
except Exception as e:
LOG.error("Remote logging configuration is wrong!")
LOG.error("Remote logging configuration is wrong, cannot apply it!")
LOG.exception(e)
def _handle_active_connectors_update(self, config):