You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.3 KiB
61 lines
1.3 KiB
import os |
|
import sys |
|
|
|
key = 'vouchercollection' |
|
|
|
if len(sys.argv) > 1: |
|
print(sys.argv[1]) |
|
key = sys.argv[1] |
|
|
|
log_path = [r"D:\logs\dinghao\cine\var\logs\quan"] |
|
|
|
path = [] |
|
for p in log_path: |
|
for r in list(os.walk(p)): |
|
# print(r[2]) |
|
if r[2]: |
|
for f in r[2]: |
|
path.append(os.path.join(r[0], f)) |
|
|
|
all_log_files = [] |
|
for f in path: |
|
if 'log.gz' in f: |
|
pass |
|
elif '.log' in f: |
|
all_log_files.append(f) |
|
else: |
|
pass |
|
# print(f) |
|
|
|
# print(all_log_files) |
|
|
|
find_result = False |
|
result_list = [] |
|
encode_error = [] |
|
|
|
for log_file in all_log_files: |
|
# print(f"检查-{log_file}") |
|
try: |
|
with open(log_file, 'r', encoding='utf-8') as f: # , encoding='utf-8' |
|
lines = f.readlines() |
|
# print(lines) |
|
for l in lines: |
|
if key in l: |
|
result_list.append((log_file, lines.index(l) + 1)) |
|
find_result = True |
|
# break |
|
|
|
# if find_result is True: |
|
# break |
|
except Exception as e: |
|
encode_error.append(log_file) |
|
# print(e) |
|
|
|
# print(f"解析失败") |
|
print("解析失败") |
|
for error in encode_error: |
|
print(error) |
|
|
|
print("结果:") |
|
for log in result_list: |
|
print(f"{log[0]}: 第{str(log[1])}行")
|
|
|