我尝试从我的日志文件中获取一个数字。这个数字是在每个“当前商店使用率”之后。我怎样才能做到这一点?我可以使用re
模块吗?从日志文件在文本文件中搜索数字?
线
2017-05-30 12:01:03,168 | WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: /opt/apache-activemq-5.12.0/bin/linux-x86-64/../../data only has 6887 mb of usable space - resetting to maximum available disk space: 6887 mb | org.apache.activemq.broker.BrokerService | WrapperSimpleAppMain
我的代码
def log_parser():
palab2 = "WARN"
logfile = open("/opt/apache-activemq-5.12.0/data/activemq.log", "r")
contenlog = logfile.readlines()
logfile.close()
for ligne in contenlog:
if palab2 in ligne:
print ("Probleme : " + ligne)
不要使用'readlines'读取整个文件。你可以遍历每一行。是的,你可以使用're'。 –