parse_saby/app/write_error_to_log.py

19 lines
712 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import datetime
TIMESTAMP = datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S")
LOG_FILE = "error_log.txt"
def write_to_log(error_message, log_file=LOG_FILE):
"""
Записывает ошибку в лог-файл с временной меткой
"""
print(error_message) # Отладочная информация
with open(log_file, 'a', encoding='utf-8') as f:
f.write(f"[{TIMESTAMP}] {error_message}\n")
def clear_to_log(log_file=LOG_FILE):
"""
Очищает лог-файл и записывает новую шапку
"""
with open(log_file, 'w', encoding='utf-8') as f:
f.write(f'=== Лог ошибок создан в {TIMESTAMP} ===\n\n')