VMiddleware/utils/Tool.py

39 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import traceback
from .ConnectPLC import PLC_Tool
from .ConfigT import ConfigT, configparser
from .LogT import logging, Log
logPath = "./logs"
config_path = "./config/config.ini"
plc_tags_config_path = "./config/plc_tags_config.ini"
config = None
try:
config = ConfigT(config_path)
except configparser.NoSectionError as e:
print("配置文件地址: %s \n %s" % (config_path, traceback.format_exc()))
def setLevel(log_level):
if log_level == "FATAL":
return logging.FATAL
elif log_level == "ERROR":
return logging.ERROR
elif log_level == "WARN":
return logging.WARN
elif log_level == "INFO":
return logging.INFO
else:
return logging.DEBUG
logger = Log(logPath, stdout_log_level=setLevel(config.stdout_log_level),
fil_log_level=setLevel(config.file_log_level)).getLogger()
logger.info("服务端口:%d 股道数量:%s", config.server_port, config.track_num)
logger.info("日志地址:%s 打印日志级别:%s 存储日志级别:%s", config.log_path, config.stdout_log_level,
config.file_log_level)
logger.info("PLC地址%s 插槽:%d 超时:%d秒 最小读取间隔:%d毫秒", config.ip_address, config.slot, config.timeout,
config.interval_plc)
logger.debug("车厢最大数:%d", config.carriage_num_max)