Log messages

Log messages#

Many primap2 functions emit log messages, which have an associated severity. The severities we use are shown in the table.

severity

used for

default

debug

useful for understanding what functions do internally

info

noteworthy information during normal processing

warning

problems which are not necessarily fatal, but should be acknowledged by the user

error

problems which need to be solved by the user

As noted, by default debug messages are not shown, all other messages are shown.

Changing what is shown#

As said, by default debug messages are not shown, as you can see here:

import primap2
import sys

from loguru import logger

logger.debug("This message will not be shown")
logger.info("This message will be shown")
2025-02-07T09:46:44.858877+0000 INFO This message will be shown

To change this, remove the standard logger and add a new logger:

logger.remove()
logger.add(sys.stderr, level="DEBUG")

logger.debug("Now you see debug messages")
logger.info("You still also see info messages")
2025-02-07 09:46:44.869 | DEBUG    | __main__:<module>:4 - Now you see debug messages
2025-02-07 09:46:44.870 | INFO     | __main__:<module>:5 - You still also see info messages

Instead of showing more, you can also show less:

logger.remove()
logger.add(sys.stderr, level="WARNING")

logger.debug("You don't see debug messages")
logger.info("You also don't see info messages")
logger.warning("But you do see all warnings")
2025-02-07 09:46:44.880 | WARNING  | __main__:<module>:6 - But you do see all warnings

Advanced usage#

It is also possible to log to a file or add more information to the logs. See the loguru documentation for details.