ecmwf / ecmwf-api-client

Python API to access ECMWF archive
Apache License 2.0
66 stars 20 forks source link

Add support for using Python's logging module instead of print statements #18

Closed cristian-codorean closed 2 years ago

cristian-codorean commented 2 years ago

Built on already existing but broken support in ecmwfapi.ECMWFDataServer and ecmwfapi.ECMWFService for passing a logging function to be used instead of the default logging function that's using print. The functionality was broken in the sense that it didn't apply to all the produced logging messages, and some of the logging messages still used print, no matter what.

That means that in order to switch to using Python's logging module one could now do something like the following:

import logging
from ecmwfapi import ECMWFDataServer

logging.basicConfig(level=logging.INFO)

def my_logging_function(msg):
    logging.info(msg)

server = ECMWFDataServer(log=my_logging_function)

Still investigating switching the API to natively use the logging module, but that's for another time. I did not want to make any breaking changes, for the time being.