thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.73k stars 840 forks source link

how to push log messages from a custom log file using remote logging? #1093

Closed rajeshAnt closed 4 months ago

rajeshAnt commented 1 year ago

Hi, I am trying to use remote logging to log messages from a custom log file to the server. But i couldn't make it work. I had modified the logs.conf file as follows.

[loggers]
keys=root, service, connector, converter, tb_connection, storage, extension, ros #added ros logger

[handlers]
keys=consoleHandler, serviceHandler, connectorHandler, converterHandler, tb_connectionHandler, storageHandler, extensionHandler, rosHandler #added ros handler for ros logs

[formatters]
keys=LogFormatter

[logger_root]
level=CRITICAL
handlers=consoleHandler

[logger_connector]
level=DEBUG
handlers=connectorHandler
formatter=LogFormatter
qualname=connector

[logger_storage]
level=DEBUG
handlers=storageHandler
formatter=LogFormatter  
qualname=storage

[logger_tb_connection]
level=DEBUG
handlers=tb_connectionHandler
formatter=LogFormatter
qualname=tb_connection

[logger_service]
level=DEBUG
handlers=serviceHandler
formatter=LogFormatter
qualname=service

[logger_converter]
level=DEBUG
handlers=connectorHandler
formatter=LogFormatter
qualname=converter

[logger_extension]
level=DEBUG
handlers=connectorHandler
formatter=LogFormatter
qualname=extension

# Added roslog handler for roslog
[logger_ros]
level=DEBUG
handlers=rosHandler
formatter=LogFormatter
qualname=ros

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=LogFormatter
args=(sys.stdout,)

[handler_connectorHandler]
level=DEBUG
class=logging.handlers.TimedRotatingFileHandler
formatter=LogFormatter
args=("./logs/connector.log", 'd', 1, 7,)

[handler_storageHandler]
level=DEBUG
class=logging.handlers.TimedRotatingFileHandler
formatter=LogFormatter
args=("./logs/storage.log", 'd', 1, 7,)

[handler_serviceHandler]
level=DEBUG
class=logging.handlers.TimedRotatingFileHandler
formatter=LogFormatter
args=("./logs/service.log", 'd', 1, 7,)

[handler_converterHandler]
level=DEBUG
class=logging.handlers.TimedRotatingFileHandler
formatter=LogFormatter
args=("./logs/converter.log", 'd', 1, 3,)

[handler_extensionHandler]
level=DEBUG
class=logging.handlers.TimedRotatingFileHandler
formatter=LogFormatter
args=("./logs/extension.log", 'd', 1, 3,)

# handler for ros logs
[handler_rosHandler]
level=DEBUG
class=logging.handlers.TimedRotatingFileHandler
formatter=LogFormatter
args=("./logs/ros.log", 'd', 1, 3,)

[handler_tb_connectionHandler]
level=DEBUG
class=logging.handlers.TimedRotatingFileHandler
formatter=LogFormatter
args=("./logs/tb_connection.log", 'd', 1, 3,)

[formatter_LogFormatter]
format='%(asctime)s - %(levelname)s - %(module)s - %(lineno)d - %(message)s'
datefmt='%Y-%m-%d %H:%M:%S'

the tb_gateway.yaml file looks like

thingsboard:
  host: thingsboard.cloud
  port: 1883
  remoteShell: true
  remoteConfiguration: true
  security:
    accessToken: *********************
  # remote_logs:
  #   enabled: true
  #   level: DEBUG
  #   interval: 5
  #   file_path: /home/weaver_one/logs/ros.log

storage:
  type: memory
  read_records_count: 100
  max_records_count: 100000
#  type: file
#  data_folder_path: ./data/
#  max_file_count: 10
#  max_read_records_count: 10
#  max_records_per_file: 10000
connectors:

 -
   name: MQTT Broker Connector
   type: mqtt
   configuration: mqtt.json

#  -
#    name: Modbus Connector
#    type: modbus
#    configuration: modbus.json

#  -
#    name: Modbus Connector
#    type: modbus
#    configuration: modbus_serial.json

#  -
#    name: OPC-UA Connector
#    type: opcua
#    configuration: opcua.json

#  -
#    name: BLE Connector
#    type: ble
#    configuration: ble.json

#  -
#    name: Custom Serial Connector
#    type: serial
#    configuration: custom_serial.json
#    class: CustomSerialConnector
samson0v commented 4 months ago

Hi @rajeshAnt, thanks for your interest in ThingsBoard IoT Gateway! Currently, we don't use logs.conf file any more. Try to use the new logs config file (logs.json) and let us know about the result.