Skip to content

Instantly share code, notes, and snippets.

@zh3389
Created April 28, 2024 08:38
Show Gist options
  • Save zh3389/7ea6bac45705d98c4e4c9dfd553a2305 to your computer and use it in GitHub Desktop.
Save zh3389/7ea6bac45705d98c4e4c9dfd553a2305 to your computer and use it in GitHub Desktop.
日志文件分析自动化通过Python解析日志文件,提取关键信息进行统计分析。
def analyze_log(log_file):
with open(log_file, 'r') as f:
lines = f.readlines()
error_count = 0
for line in lines:
if "ERROR" in line:
error_count += 1
print(f"日志文件中包含 {error_count} 条错误记录。")
# 使用示例:
analyze_log('application.log')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment