Setting Up Logging

Basic logging

discodo logs several information via the logging python module like discord.py. It is strongly recommended to configure the logging module, as you can’t see some error if it is not set up. You can configure the logging module as simple as:

import logging

logging.basicConfig(level=logging.INFO)

Placed at the start of the code. This will output the logs from all libraries which use the logging module, including discodo, to the console.

The level argument specifies what level of events to log and can be any of CRITICAL, ERROR, WARNING, INFO, and DEBUG and default value is WARNING

For more information, check the documentation of the logging module.

Use rich formatter

Also, discodo uses rich to improve log readability. rich is an library for rich text and formatting in the terminal. To output the log to the terminal using rich, you can set it as follows:

import logging
from rich.logging import RichHandler

logging.basicConfig(level=logging.INFO, format="%(name)s :\t%(message)s", handlers=[RichHandler(rich_tracebacks=True)])

Because rich displays the log level separately, remove the level from the format argument, and set rich_tracebacks to True for formatting tracebacks.

When you set this, the log will be formatted as follows:

Rich formatter example