首页 > 解决方案 > Python 排除行正则表达式字符串等(python 日志记录/Ookla 服务器

问题描述

我正在使用 Ookla Server,它在端口 8080 上运行,并对移动应用程序(不是 HTTP)端进行速度测试

它记录了太多冗长,它设置为应用程序,唯一的错误是另一个选项

它每秒记录这样的数据,日志太大太多信息


 [14/Jun/2021:17:46:46 GMT] "Disconnect NetException: Connection reset by peer"  "" "" 
[14/Jun/2021:17:46:46 GMT] "Disconnect NetException: Connection reset by peer"  "" "" 
[14/Jun/2021:17:46:46 GMT] "Disconnect NetException: Connection reset by peer"  "" "" 
[14/Jun/2021:17:46:47 GMT] "TCP uptime: 101 - total current: 2, queued: 0, blocked: 0, queueFull: 0, concurrent: 6, currentThreads: 4"  "" "" 

我尝试了不同的选项来排除“TCP”行,例如(从我的 ooklaserver.properties 配置中)与我在堆栈溢出中找到的正则表达式数据

#logging.loggers.app.name = Application
logging.loggers.app.channel.class = FileChannel
#logging.loggers.app.channel.pattern = %Y-%m-%d %H:%M:%S [%P - %I] [%p] %t
#logging.loggers.app.channel.pattern = %[client_plaintext] - %[session] [%d/%b/%Y:%H:%M:%S %Z] "%t" %[status] %[size] "%[referer]" "%[useragent]"
#logging.loggers.app.channel.pattern = %[client_plaintext] - %[session] [%d/%b/%Y:%H:%M:%S %Z] "%[referer]" "%[useragent]"
logging.loggers.app.channel.pattern =  sub(r'(?<!\b[ia])t\b', '', TCP) (r'^(?!/TCP).*$') %[client_plaintext] - [%d/%b/%Y:%H:%M:%S %Z] "%t" %[size] "%[referer]" "%[useragent]" 

logging.loggers.app.channel.path = ${application.dir}/ooklaserver.log

也许排除部分必须在不同的命令中运行并重写?基本上,我只想记录 IP 和时间...

尝试 了如何在 Python 中使用正则表达式排除特定字符串? 使用正则表达式排除字符串搜索中的字符? 如何从正则表达式组中排除字符? 排除单词/字符串的正则表达式 非常感谢!

标签: pythonlogging

解决方案


推荐阅读