File size: 905 Bytes
716138f |
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 28 |
import logging
import os
from datetime import datetime
def setup_logger(log_level=logging.INFO):
"""Configure and return a logger instance for the application."""
# Create logs directory if it doesn't exist
log_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logs')
os.makedirs(log_dir, exist_ok=True)
# Create unique log filename with timestamp
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
log_file = os.path.join(log_dir, f'cv_parser_{timestamp}.log')
# Configure logging
logging.basicConfig(
level=log_level,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_file),
logging.StreamHandler() # Also log to console
]
)
return logging.getLogger('cv_parser')
# Create a default logger instance
logger = setup_logger() |