[Python] logger from jupyter notebook: does not work unless calling the root logger at least...

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I would like to see the logging produced by some python code from within a Jupyter notebook (logging version '0.5.1.2', python 3.12).

    If I run the following code:

    import logging

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    logger.info("logging test")


    I get no output.

    But if I call the root logging first in a notebook cell:

    import logging

    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    logging.info("logging test") # calling the root logger


    I get the expected "logging test", and every other subsequent logged message, like:

    logger.info("another logging test")


    works correctly.

    So within the same session, if I do not call the root logger at least once, no logging message is shown. But if I run the root logger at least once, all works correctly.

    Any idea or explanation why is it the case, or if I am doing something wrong?

    Continue reading...

Compartilhe esta Página