Read Python application logs
On application hosting, the panel console is your main window into the Python process. Knowing where messages go, how to structure them and how to read a traceback keeps you from debugging blind.
1. Where output goes
The panel starts your command and captures two separate streams:
- stdout:
print()and normal output. - stderr: warnings, errors and uncaught tracebacks.
Both show up in the console, often interleaved, and their order is not guaranteed. Another trap: when output is not a terminal, Python buffers it. Messages may arrive late, or be lost entirely if the process is killed abruptly. Set PYTHONUNBUFFERED=1 in the panel environment variables, or pass flush=True to print().
2. Structure output with logging
print() is fine for a quick test, not for a service. The logging module adds a level, a timestamp, a logger name and a configurable destination.
import logging
import os
import sys
logging.basicConfig(
level=os.environ.get("LOG_LEVEL", "INFO").upper(),
format="%(asctime)s %(levelname)s %(name)s %(message)s",
stream=sys.stdout,
force=True,
)
log = logging.getLogger("app")
log.info("starting")Keep INFO in production. Turn on DEBUG through an environment variable while investigating, then switch back: a noisy level fills the console and may expose internal data. Never log tokens, passwords or full connection strings. For an exception, log.exception("context") keeps the complete trace.
3. Read a traceback
Python prints the call stack from oldest to newest. The decisive line is the last one: exception type and message. Blocks such as During handling of the above exception or The above exception was the direct cause indicate chained exceptions; look for the deepest cause.
Lines like File "...", line N, in ... give the location, including inside dependencies. Common signatures:
ModuleNotFoundError: a dependency is missing fromrequirements.txtor failed to install.SyntaxError: invalid code, the app never starts.Address already in use: another process already holds the port.KeyErroron an environment variable: the secret is not set in the panel.
4. Restart loops
If the process exits, the panel may start it again. A short loop repeats the same error and pushes the first lines out of view. Read the beginning of the output after a restart: that is where the original cause sits. If the console truncates history, reproduce locally with python main.py and the same variables.
5. Verify and troubleshoot
- Restart with
LOG_LEVEL=DEBUG, reproduce the issue, then setINFOagain. - Confirm each expected message appears exactly once.
- Check dependencies with
pip install -r requirements.txtlocally. - Remove debugging
print()calls before redeploying.
A readable console beats a long log file nobody checks.
Advertisement
Was this article helpful?
Read next
- Configure Python environment variablesRead variables with os.environ, set them in the panel and rotate secrets.
- Use a Python virtual environmentIsolate dependencies with venv, then adapt the method to managed hosting and a VPS.
- Host a Python Discord botSet up discord.py, intents, reconnection and token protection.