applogger.py - Configure logging for the BookServer

Imports

These are listed in the order prescribed by PEP 8.

Standard library

import logging
import sys
 

Third-party imports

None.

Local application imports

None.

Logging

rslogger = logging.getLogger("runestone")
rslogger.setLevel(logging.DEBUG)

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
    "%(levelname)s - %(asctime)s - %(funcName)s - %(message)s"
)
handler.setFormatter(formatter)
rslogger.addHandler(handler)
 

To turn on debugging for FastAPI and the database package:

1from fastapi.logger import logger
2import logging
3logger.setLevel(logging.DEBUG)

Otherwise, FastAPI logs at the default level. There is good info here on setting up logging. There is also good info on hooking into the gunicorn logging system when you deploy here.