Logging in FastAPI applications

Enabling Logtail only in production

Want more?

This lesson for enrolled students only. Join the course to unlock it!

You can see the code changes implemented in this lecture below.

If you have purchased the course in a different platform, you still have access to the code changes per lecture here on Teclado. The lecture video and lecture notes remain locked.
Join course for $30

Modified files

storeapi/logging_conf.py
--- 
+++ 
@@ -20,6 +20,11 @@
         if "email" in record.__dict__:
             record.email = obfuscated(record.email, self.obfuscated_length)
         return True
+
+
+handlers = ["default", "rotating_file"]
+if config.ENV_STATE == "prod":
+    handlers = ["default", "rotating_file", "logtail"]


 def configure_logging() -> None:
@@ -81,7 +86,7 @@
             "loggers": {
                 "uvicorn": {"handlers": ["default", "rotating_file"], "level": "INFO"},
                 "storeapi": {
-                    "handlers": ["default", "rotating_file", "logtail"],
+                    "handlers": handlers,
                     "level": "DEBUG" if isinstance(config, DevConfig) else "INFO",
                     "propagate": False,
                 },