Closed Blunde1 closed 8 months ago
Looking into the Python logging
module. E.g.
import logging
def set_logging_level(level):
"""
Adjust the logging level to control output. Use 'OFF' to disable all logging.
level: str - Desired logging level ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL', 'OFF').
"""
if level.upper() == 'OFF':
# Disables all logging by setting the highest possible level
critical_level = getattr(logging, "CRITICAL", None)
logging.getLogger().setLevel(critical_level+1) # Disables all logging
else:
# Convert string level to logging level and set it
numeric_level = getattr(logging, level.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError(f'Invalid log level: {level}')
logging.getLogger().setLevel(numeric_level)
# Example initialization to enable logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
# Example usage:
set_logging_level('DEBUG') # Enable debug logging
logging.debug('This is a debug message.')
set_logging_level('OFF') # Disable all logging
logging.info('This message will not appear.')
set_logging_level('INFO') # Re-enable logging at INFO level
logging.info('This is an info message.')
Or, a direct level option > 1 will print. Sub functions are called with verbose=verbose-1
and prints if verbose > 0
.
Add a
verbose
option tofit
andtransport
. And all other functions it calls. Allow them to print useful information. The default should beFalse
.Examples of things to print: