You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In library mode, it is strongly advised not to declare any root handler in the library code.
Unfortunately, that’s what we do in {{h2o.py}} with the {{logging.basicConfig()}} statement. We should then just delete this instruction.
In both Py2.7 and Py3.5+, this will just let Python raise a warning if the h2o logger is used but the user didn’t define any handler for it (nor any parent handler like the root handler…) and all logs at warning or error level will then be redirected to stderr.
This means that in this case, the {{info}} level is not logged at all.
Note that currently (strangely?), the h2o logger is used only in {{config}} module, mainly to log config errors, so I would recommend to just delete the {{logging.basicConfig()}} statement mentionned earlier.
h3. Moving further
Py client is using {{print}} in many situations where the Python logger would be more appropriate: warnings, error messages, requests response…
I think we should switch to a logger for those situations to provide the user with more control on what/where to log.
In this case, although it is not usually recommended to define handlers in libraries, we could even consider to provide a basic console handler for the h2o logger and use it only if the user didn’t define its own handlers (only for Py3):
{code:python}import logging
logger = logging.getLogger('h2o')
if PY3 and not logger.hasHandlers():
logger.setLevel(level=logging.INFO)
logger.addHandler(logging.StreamHandler()) # log to console{code}
The text was updated successfully, but these errors were encountered:
In library mode, it is strongly advised not to declare any root handler in the library code.
Unfortunately, that’s what we do in {{h2o.py}} with the {{logging.basicConfig()}} statement.
We should then just delete this instruction.
In both Py2.7 and Py3.5+, this will just let Python raise a warning if the h2o logger is used but the user didn’t define any handler for it (nor any parent handler like the root handler…) and all logs at warning or error level will then be redirected to stderr.
This means that in this case, the {{info}} level is not logged at all.
Note that currently (strangely?), the h2o logger is used only in {{config}} module, mainly to log config errors, so I would recommend to just delete the {{logging.basicConfig()}} statement mentionned earlier.
h3. Moving further
Py client is using {{print}} in many situations where the Python logger would be more appropriate: warnings, error messages, requests response…
I think we should switch to a logger for those situations to provide the user with more control on what/where to log.
In this case, although it is not usually recommended to define handlers in libraries, we could even consider to provide a basic console handler for the h2o logger and use it only if the user didn’t define its own handlers (only for Py3):
{code:python}import logging
logger = logging.getLogger('h2o')
if PY3 and not logger.hasHandlers():
logger.setLevel(level=logging.INFO)
logger.addHandler(logging.StreamHandler()) # log to console{code}
The text was updated successfully, but these errors were encountered: