Created
April 28, 2024 08:38
-
-
Save zh3389/7ea6bac45705d98c4e4c9dfd553a2305 to your computer and use it in GitHub Desktop.
日志文件分析自动化通过Python解析日志文件,提取关键信息进行统计分析。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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