Deal with unexpected chars in log

This commit is contained in:
Brian Read 2024-06-14 15:48:14 +01:00
parent b5970977e6
commit 528bebf7a7
2 changed files with 25 additions and 20 deletions

View File

@ -5,7 +5,7 @@
<html><head> <html><head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>SMEServer Mailstats</title> <title>SMEServer Mailstats</title>
<link rel='stylesheet' type='text/css' href='../css/mailstats.css' /> <link rel='stylesheet' type='text/css' href='css/mailstats.css' />
<!-- Check links --> <!-- Check links -->
<script> <script>
function LinkCheck(url){ function LinkCheck(url){

View File

@ -31,6 +31,7 @@ from collections import defaultdict
import smtplib import smtplib
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText from email.mime.text import MIMEText
import codecs
Mailstats_version = '1.2' Mailstats_version = '1.2'
@ -188,7 +189,8 @@ def read_in_yesterday_log_file(file_path):
# Get current date and calculate yesterday's date # Get current date and calculate yesterday's date
log_entries = [] log_entries = []
skip_record_count = 0; skip_record_count = 0;
with open(file_path, 'r') as file: with codecs.open(file_path, 'rb','utf-8', errors='replace') as file:
try:
for Line in file: for Line in file:
#extract time stamp #extract time stamp
try: try:
@ -207,6 +209,9 @@ def read_in_yesterday_log_file(file_path):
print(f"ValueError {e} on timestamp extract {timestamp_str}:{entry[1]}") print(f"ValueError {e} on timestamp extract {timestamp_str}:{entry[1]}")
if timestamp.date() == yesterday.date(): if timestamp.date() == yesterday.date():
log_entries.append((timestamp, entry[1])) log_entries.append((timestamp, entry[1]))
except UnicodeDecodeError as e:
#print(f"{Line} {len(log_entries)} {e} ")
pass
return [log_entries,skip_record_count] return [log_entries,skip_record_count]
def filter_summary_records(log_entries): def filter_summary_records(log_entries):