cerfacs-globc / icclim

icclim: Python library for climate indices and climate indicators calculation.
https://icclim.readthedocs.io/en/latest/
Apache License 2.0
84 stars 32 forks source link

Suppress icclim logger output #308

Open ritviksahajpal opened 8 months ago

ritviksahajpal commented 8 months ago

Description

I would like to suppress all logger output from icclim, or maybe have the option to choose the level at which icclim outputs

Minimal reproducible example

class NullHandler(logging.Handler):
    def emit(self, record):
        pass

logger = logging.getLogger('icclim')
logger.addHandler(NullHandler())
logger.propagate = False

Output received

By adding the code above in the code, I was expecting to suppress all logging output from icclim, but it did not work. Can you help me figure out what code to use to suppress/control icclim logger output

bzah commented 8 months ago

When calling icclim.index, you can silence logs by setting logs_verbosity="SILENT". Only errors are then reported. For now we use the root logger to emit our logs, but it would probably make sense to have a named logger that users could easily suppress like in your attempt.