From 340d48876b65bf05d1d9412d371221aec8114780 Mon Sep 17 00:00:00 2001 From: gitea Date: Thu, 1 Aug 2024 19:15:08 +0800 Subject: [PATCH] =?UTF-8?q?10.=20[APIs:=20all]:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86=20logger.setLevel(INFO)=EF=BC=8C=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BF=99=E4=B8=AA=EF=BC=8C=E5=8D=95=E4=B8=AA?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=86=85=E6=89=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aio/README.md | 3 ++- aio/code/aio.py | 5 +++-- aio/code/automatic_test/btn_functions.py | 3 ++- aio/code/automatic_test/do_brake.py | 5 +++-- aio/code/automatic_test/do_current.py | 4 +++- aio/code/commons/clibs.py | 15 +++++---------- aio/code/commons/openapi.py | 6 ++++-- aio/code/data_process/brake.py | 3 ++- aio/code/data_process/current.py | 3 ++- aio/code/data_process/iso.py | 3 ++- aio/code/data_process/wavelogger.py | 3 ++- aio/code/durable_action/factory_test.py | 4 +++- 12 files changed, 33 insertions(+), 24 deletions(-) diff --git a/aio/README.md b/aio/README.md index 08af704..65d2151 100644 --- a/aio/README.md +++ b/aio/README.md @@ -594,4 +594,5 @@ v0.2.0.5(2024/07/31) 8. [APIs: aio.py]: 将日志框输出的内容,也保存至日志文件 9. [APIs: do_brake.py] - 修改获取初始速度的逻辑,只获取configs文件中配置的时间内的速度 - - 新增 configs 参数 single_brake,可针对特定条件做测试 \ No newline at end of file + - 新增 configs 参数 single_brake,可针对特定条件做测试 +10. [APIs: all]: 添加了 logger.setLevel(INFO),只有添加这个,单个模块内才生效 diff --git a/aio/code/aio.py b/aio/code/aio.py index f41051a..7db0277 100644 --- a/aio/code/aio.py +++ b/aio/code/aio.py @@ -14,7 +14,7 @@ from commons import openapi, clibs from matplotlib.pyplot import rcParams, figure, subplots_adjust, close from matplotlib import use from pandas import DataFrame, read_excel -import logging +from logging import getLogger, INFO with open(clibs.log_data, 'w') as _: for i in range(1, 11): @@ -22,7 +22,8 @@ with open(clibs.log_data, 'w') as _: remove(f'{clibs.log_data}.{i}') except FileNotFoundError: pass -logger = logging.getLogger(__file__) +logger = getLogger(__file__) +logger.setLevel(INFO) logger.info("日志文件初始化完成...") use('Agg') diff --git a/aio/code/automatic_test/btn_functions.py b/aio/code/automatic_test/btn_functions.py index 42b93f6..48d9378 100644 --- a/aio/code/automatic_test/btn_functions.py +++ b/aio/code/automatic_test/btn_functions.py @@ -1,10 +1,11 @@ from json import loads from sys import argv -from logging import getLogger +from logging import getLogger, INFO from commons import clibs tab_name = clibs.tab_names['at'] logger = getLogger(__file__) +logger.setLevel(INFO) def trigger_estop(md, w2t): diff --git a/aio/code/automatic_test/do_brake.py b/aio/code/automatic_test/do_brake.py index 844ac92..5436903 100644 --- a/aio/code/automatic_test/do_brake.py +++ b/aio/code/automatic_test/do_brake.py @@ -5,11 +5,12 @@ from paramiko import SSHClient, AutoAddPolicy from json import loads from openpyxl import load_workbook from pandas import DataFrame, concat -from logging import getLogger +from logging import getLogger, INFO from commons import clibs tab_name = clibs.tab_names['at'] logger = getLogger(__file__) +logger.setLevel(INFO) def check_files(path, loadsel, data_dirs, data_files, w2t): @@ -105,7 +106,7 @@ def run_rl(path, loadsel, hr, md, config_file, result_dirs, w2t): ws = wb['Target'] write_diagnosis = float(ws.cell(row=3, column=10).value) get_init_speed = float(ws.cell(row=4, column=10).value) - single_brake = ws.cell(row=5, column=10).value + single_brake = str(ws.cell(row=5, column=10).value) if ws.cell(row=1, column=1).value == 'positive': md.write_pon(1) diff --git a/aio/code/automatic_test/do_current.py b/aio/code/automatic_test/do_current.py index 9b8ec12..f26950c 100644 --- a/aio/code/automatic_test/do_current.py +++ b/aio/code/automatic_test/do_current.py @@ -4,10 +4,12 @@ from sys import argv from paramiko import SSHClient, AutoAddPolicy from json import loads from pandas import DataFrame, concat -from logging import getLogger +from logging import getLogger, INFO from commons import clibs logger = getLogger(__file__) +logger.setLevel(INFO) + tab_name = clibs.tab_names['at'] display_pdo_params = [ {"name": "hw_joint_vel_feedback", "channel": 0}, diff --git a/aio/code/commons/clibs.py b/aio/code/commons/clibs.py index 2fa9c7f..9aeee42 100644 --- a/aio/code/commons/clibs.py +++ b/aio/code/commons/clibs.py @@ -38,21 +38,16 @@ durable_data_current_max = { 'axis6': [0 for _ in range(18)], } -fmt = Formatter('%(asctime)s # %(levelname)s-%(filename)s-%(funcName)s # %(message)s') -# file_handler = logging.FileHandler(log_data) -# file_handler = RotatingFileHandler(filename=log_data, backupCount=10, maxBytes=50*1024*1024, encoding='utf-8') file_handler = ConcurrentRotatingFileHandler(filename=log_data, backupCount=10, maxBytes=50*1024*1024, encoding='utf-8') -file_handler.setFormatter(fmt) file_handler.setLevel(INFO) console_handler = StreamHandler() -console_handler.setFormatter(fmt) -console_handler.setLevel(ERROR) +console_handler.setLevel(WARNING) -# basicConfig(level=WARNING, # for product -basicConfig(level=WARNING, +basicConfig( # level=INFO, datefmt='%Y-%m-%dT%H:%M:%S', - # handlers=[file_handler]) # for product - handlers=[file_handler, console_handler]) + format='%(asctime)s # %(levelname)s-%(filename)s-%(funcName)s # %(message)s', + handlers=[file_handler, console_handler], + ) class GetThreadResult(Thread): diff --git a/aio/code/commons/openapi.py b/aio/code/commons/openapi.py index 95b422e..5908960 100644 --- a/aio/code/commons/openapi.py +++ b/aio/code/commons/openapi.py @@ -6,10 +6,12 @@ from time import time, sleep from pymodbus.client.tcp import ModbusTcpClient from pymodbus.payload import BinaryPayloadDecoder, BinaryPayloadBuilder from pymodbus.constants import Endian -from logging import getLogger +from logging import getLogger, INFO from commons import clibs logger = getLogger(__file__) +logger.setLevel(INFO) + class ModbusRequest(object): def __init__(self, w2t): @@ -261,7 +263,7 @@ class HmiRequest(object): def msg_storage(self, response, flag=0): # response是解码后的字符串 messages = self.c_msg if flag == 0 else self.c_msg_xs - logger.warning(f"{loads(response)}") + logger.info(f"{loads(response)}") if 'move.monitor' in response: pass elif len(messages) < 10000: diff --git a/aio/code/data_process/brake.py b/aio/code/data_process/brake.py index b2f1333..1b1cfaa 100644 --- a/aio/code/data_process/brake.py +++ b/aio/code/data_process/brake.py @@ -5,10 +5,11 @@ from openpyxl import load_workbook from time import time, sleep, strftime, localtime from threading import Thread from pandas import read_csv -from logging import getLogger +from logging import getLogger, INFO from commons import clibs logger = getLogger(__file__) +logger.setLevel(INFO) def check_files(path, raw_data_dirs, result_files, w2t): diff --git a/aio/code/data_process/current.py b/aio/code/data_process/current.py index 19f5876..c4fc7c3 100644 --- a/aio/code/data_process/current.py +++ b/aio/code/data_process/current.py @@ -5,10 +5,11 @@ from re import match from threading import Thread from time import sleep from csv import reader, writer -from logging import getLogger +from logging import getLogger, INFO from commons import clibs logger = getLogger(__file__) +logger.setLevel(INFO) def w2t_local(msg, wait, w2t): diff --git a/aio/code/data_process/iso.py b/aio/code/data_process/iso.py index 5318d64..91397af 100644 --- a/aio/code/data_process/iso.py +++ b/aio/code/data_process/iso.py @@ -3,10 +3,11 @@ import pdfplumber from openpyxl import load_workbook from os import remove from sys import argv -from logging import getLogger +from logging import getLogger, INFO from commons import clibs logger = getLogger(__file__) +logger.setLevel(INFO) def p_iso(file, p_files, ws, tmpfile): diff --git a/aio/code/data_process/wavelogger.py b/aio/code/data_process/wavelogger.py index 625b2a5..013b527 100644 --- a/aio/code/data_process/wavelogger.py +++ b/aio/code/data_process/wavelogger.py @@ -2,10 +2,11 @@ from pandas import read_csv from csv import reader from sys import argv from openpyxl import Workbook -from logging import getLogger +from logging import getLogger, INFO from commons import clibs logger = getLogger(__file__) +logger.setLevel(INFO) def find_point(bof, step, pos, data_file, flag, df, row, w2t): diff --git a/aio/code/durable_action/factory_test.py b/aio/code/durable_action/factory_test.py index 930a1d2..7e725fa 100644 --- a/aio/code/durable_action/factory_test.py +++ b/aio/code/durable_action/factory_test.py @@ -6,10 +6,12 @@ from openpyxl import load_workbook from math import sqrt from numpy import power from csv import writer -from logging import getLogger +from logging import getLogger, INFO from commons import clibs logger = getLogger(__file__) +logger.setLevel(INFO) + tab_name = clibs.tab_names['da'] count = 0 display_pdo_params = [