equinor / graphite-maps

Graph informed triangular ensemble-to-posterior maps
GNU General Public License v3.0
1 stars 0 forks source link

Add a `verbose` option #14

Closed Blunde1 closed 8 months ago

Blunde1 commented 9 months ago

Add a verbose option to fit and transport. And all other functions it calls. Allow them to print useful information. The default should be False.

Examples of things to print:

Blunde1 commented 9 months ago

Looking into the Python loggingmodule. 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.