为了方便测试这款插件的功能,我们可以写一段代码 来测试
import logging
import time
# 配置日志
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
# 日志消息中的字典内容
log_message = """
{413867144: {'20240103153620': {'speed': 0.0, 'lgt': 111.209307, 'lat': 23.416535, 'shipname': '海顺5689', 'heading': 335, 'point': (883, 138), 'source': 'not_actual', 'distance': 207.86338638073946, 'mark': 0}}, 413843228: {'20240103153312': {'speed': 0.0, 'lgt': 111.208187, 'lat': 23.4152, 'shipname': '桂平滨海6608', 'heading': 181, 'point': (530, 143), 'source': 'actual', 'distance': 329.6938214076262, 'mark': 1}}, 413907023: {'20240103153620': {'speed': 0.0, 'lgt': 111.208513, 'lat': 23.41654, 'shipname': '桂外5369', 'heading': 256, 'point': (901, 142), 'source': 'not_actual', 'distance': 287.09264117973476, 'mark': 0}}, 413953829: {'20240103153620': {'speed': 0.0, 'lgt': 111.209688, 'lat': 23.415503, 'shipname': '顺舟5678', 'heading': 285, 'point': (488, 138), 'source': 'not_actual', 'distance': 173.78971359529245, 'mark': 0}}, 413776394: {'20240103153620': {'speed': 0.0, 'lgt': 111.209568, 'lat': 23.415647, 'shipname': '南翔6698', 'heading': 89, 'point': (539, 138), 'source': 'not_actual', 'distance': 180.52259966568073, 'mark': 0}}, 413846891: {'20240103153620': {'speed': 0.3, 'lgt': 111.21542783629074, 'lat': 23.41745351917435, 'shipname': '桂平宏远1338', 'heading': 281, 'point': (493, 188), 'source': 'not_actual', 'distance': 450.8102099768608, 'mark': 0}}, 413872354: {'20240103153350': {'speed': 0.0, 'lgt': 111.208015, 'lat': 23.416353, 'shipname': 'Unknown Ship', 'heading': 0, 'point': (842, 144), 'source': 'actual', 'distance': 334.52581498110015, 'mark': 1}}, 413872633: {'20240103153406': {'speed': 0.0, 'lgt': 111.215657, 'lat': 23.417205, 'shipname': 'Unknown Ship', 'heading': 511, 'point': (648, 192), 'source': 'actual', 'distance': 464.541916079419, 'mark': 1}}, 413837307: {'20240103153620': {'speed': 6.2, 'lgt': 111.20449863345068, 'lat': 23.41495256410014, 'shipname': '藤县益航5678', 'heading': 261, 'point': (644, 150), 'source': 'not_actual', 'distance': 702.7278111208868, 'mark': 0}}, 413906906: {'20240103153418': {'speed': 0.0, 'lgt': 111.209533, 'lat': 23.415717, 'shipname': '鸿丰3568', 'heading': 70, 'point': (562, 138), 'source': 'actual', 'distance': 182.17568749024446, 'mark': 1}}, 413847717: {'20240103153620': {'speed': 0.0, 'lgt': 111.207103, 'lat': 23.41491, 'shipname': '平南志顺899', 'heading': 164, 'point': (536, 146), 'source': 'not_actual', 'distance': 444.9089945984533, 'mark': 0}}, 413842226: {'20240103153620': {'speed': 0.0, 'lgt': 111.206535, 'lat': 23.41604, 'shipname': '海宇158', 'heading': 115, 'point': (790, 148), 'source': 'not_actual', 'distance': 483.9994425700712, 'mark': 0}}, 413841473: {'20240103153620': {'speed': 0.0, 'lgt': 111.20654, 'lat': 23.415897, 'shipname': '东运2368', 'heading': 31, 'point': (756, 148), 'source': 'not_actual', 'distance': 483.8349940031178, 'mark': 0}}, 413983741: {'20240103153452': {'speed': 0.1, 'lgt': 111.208623, 'lat': 23.416493, 'shipname': '谢圩978', 'heading': 189, 'point': (880, 142), 'source': 'actual', 'distance': 275.112567750152, 'mark': 1}}, 413994719: {'20240103153503': {'speed': 0.0, 'lgt': 111.209293, 'lat': 23.416692, 'shipname': '邕航666', 'heading': 64, 'point': (962, 138), 'source': 'actual', 'distance': 214.29271021424196, 'mark': 1}}, 999999832: {'20240103153509': {'speed': 0.0, 'lgt': 111.206593, 'lat': 23.414372, 'shipname': 'Unknown Ship', 'heading': 511, 'point': (477, 146), 'source': 'actual', 'distance': 513.7291676993656, 'mark': 1}}, 413794377: {'20240103153620': {'speed': 0.0, 'lgt': 111.209315, 'lat': 23.416755, 'shipname': '南源9689', 'heading': 0, 'point': (996, 138), 'source': 'not_actual', 'distance': 214.58343588760144, 'mark': 0}}, 413866459: {'20240103153620': {'speed': 0.0, 'lgt': 111.208838, 'lat': 23.415437, 'shipname': '海顺5158', 'heading': 0, 'point': (540, 141), 'source': 'not_actual', 'distance': 258.53500456207547, 'mark': 0}}, 413872228: {'20240103153620': {'speed': 0.0, 'lgt': 111.207055, 'lat': 23.415047, 'shipname': '海安366', 'heading': 0, 'point': (562, 146), 'source': 'not_actual', 'distance': 445.49611633144383, 'mark': 0}}, 413876046: {'20240103153606': {'speed': 5.5, 'lgt': 111.20926, 'lat': 23.415925, 'shipname': 'Unknown Ship', 'heading': 259, 'point': (647, 139), 'source': 'actual', 'distance': 206.4950364902942, 'mark': 1}}}
"""
# 将字符串转换为字典
import ast
log_data = ast.literal_eval(log_message)
# 定义日志等级顺序
log_levels = [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]
# 循环输出字典中的每个条目,并按照日志等级递增的顺序输出
while True:
for key, value in log_data.items():
for log_level in log_levels:
logger.log(log_level, f"Key: {key}, Value: {value}")
time.sleep(1) # 间隔1秒
logger.log(logging.DEBUG, "this is not log message! this is not log message!")
输出效果:? 控制台不同等级的日志 会被标记不同的颜色
算了 还是直接录个 视频介绍吧: