Prometheus / logging_config.py
tbels89's picture
v1.0 new modular format
f80362a
Raw History Blame Contribute Delete
646 Bytes
# 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.")