# aiva/logging.py
import logging

# Define custom log levels (optional, but good practice)
LOG_LEVELS = {
    'DEBUG': logging.DEBUG,
    'INFO': logging.INFO,
    'WARNING': logging.WARNING,
    'ERROR': logging.ERROR,
    'CRITICAL': logging.CRITICAL
}

# Function to configure logging (can be extended with file handlers, etc.)
def configure_logging(level='INFO', filename=None):
    """Configures the global logging settings."""
    numeric_level = LOG_LEVELS.get(level.upper(), logging.INFO) # Default to INFO if invalid
    if not isinstance(numeric_level, int):
        raise ValueError(f'Invalid log level: {level}')

    logging.basicConfig(level=numeric_level, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    if filename:
        # Add a file handler (optional)
        file_handler = logging.FileHandler(filename)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        file_handler.setFormatter(formatter)
        logging.getLogger('').addHandler(file_handler)


if __name__ == '__main__':
    # Example usage
    configure_logging(level='DEBUG')  # Set the global logging level
    logger = logging.getLogger('example')
    logger.debug('This is a debug message')
    logger.info('This is an info message')
    logger.warning('This is a warning message')
    logger.error('This is an error message')
    logger.critical('This is a critical message')