Spaces:
Sleeping
Sleeping
import logging | |
import json | |
from logging.handlers import TimedRotatingFileHandler | |
from datetime import datetime | |
from pathlib import Path | |
parent_path = Path(__file__).resolve().parent.parent.parent | |
final_path = parent_path/'logs'/'translation_error.log' | |
# Configure logging with TimedRotatingFileHandler | |
logging.basicConfig(level=logging.ERROR, | |
format='%(asctime)s %(levelname)s %(message)s') | |
# Create a TimedRotatingFileHandler | |
handler = TimedRotatingFileHandler(filename=final_path, when='W0', interval=1, backupCount=0, encoding='utf-8') | |
# Set the log file name format (optional) | |
handler.suffix = "%Y-%m-%d_%H-%M-%S.log" | |
# Set the logging format | |
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s')) | |
logger = logging.getLogger().addHandler(handler) | |
def log_error(error_message): | |
logging.error(error_message) |