File size: 1,451 Bytes
8e4018d a6f0289 53ccced 141cd60 53ccced 5819cb0 53ccced 5819cb0 141cd60 53ccced 5819cb0 141cd60 53ccced 141cd60 53ccced 5819cb0 53ccced 5819cb0 53ccced 5819cb0 53ccced |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import logging
import sys
from datetime import datetime
from pathlib import Path
# Global logger configuration
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOG_LEVEL = logging.INFO
def setup_logging(log_level=LOG_LEVEL):
"""Setup logging configuration"""
logging.basicConfig(
level=log_level,
format=LOG_FORMAT,
handlers=[
logging.StreamHandler(sys.stdout),
]
)
def get_logger(name):
"""Get a logger instance"""
return logging.getLogger(name)
def log_error(logger, error_msg, exception=None, context=None):
"""Log error with additional context"""
full_msg = f"{error_msg}"
if context:
full_msg += f" | Context: {context}"
if exception:
full_msg += f" | Exception: {str(exception)}"
logger.error(full_msg)
def log_info(logger, msg, context=None):
"""Log info with additional context"""
full_msg = f"{msg}"
if context:
full_msg += f" | Context: {context}"
logger.info(full_msg)
def log_warning(logger, msg, context=None):
"""Log warning with additional context"""
full_msg = f"{msg}"
if context:
full_msg += f" | Context: {context}"
logger.warning(full_msg)
def log_debug(logger, msg, context=None):
"""Log debug with additional context"""
full_msg = f"{msg}"
if context:
full_msg += f" | Context: {context}"
logger.debug(full_msg) |