File size: 646 Bytes
f80362a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# logging_config.py

import logging
from logging.handlers import RotatingFileHandler
import os

LOG_FILE_PATH = "./logs/app.log"

if not os.path.exists(LOG_FILE_PATH):
    with open(LOG_FILE_PATH, 'w') as log_file:
        log_file.write("")  # Create an empty file

# Setup logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(levelname)s:%(name)s:%(funcName)s:%(message)s',
    handlers=[
        RotatingFileHandler(LOG_FILE_PATH, maxBytes=5*1024*1024, backupCount=3),
        logging.StreamHandler()
    ]
)
logger = logging.getLogger(__name__)

# Test logging
logger.info("Logging setup initialized successfully.")