File size: 886 Bytes
c732202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)