How to read your app's logs in the console
Find out why your Schokr app is misbehaving by reading console output, making logs show up instantly, and writing logs to a file.
Updated · 1 min read
Everything your app writes to standard output and standard error shows up in your server's console on Schokr. That is the first place to look when an app crashes, will not start, or behaves oddly.
What you see in the console
- Output from the template's startup, such as dependency installs.
- Your app's
console.log,console.errorandprintoutput. - Stack traces when the app crashes.
- Messages when the server starts, stops or is killed.
The console shows recent output, not unlimited history. For long-term logs, also write to a file (see below).
Make Python logs appear immediately
Python buffers output when it is not attached to a terminal, so print lines can appear late or not at all before a crash. Fix it with one of:
print("Started", flush=True)
import sys
sys.stdout.reconfigure(line_buffering=True)
Or set the environment variable PYTHONUNBUFFERED=1, or run Python with -u.
Use a proper logger
Node.js
const log = (level, msg, extra = {}) =>
console.log(JSON.stringify({ time: new Date().toISOString(), level, msg, ...extra }))
log('info', 'Server started', { port: 25571 })
For larger apps, pino gives fast structured logs and is built into Fastify.
Python
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
log = logging.getLogger("app")
log.info("Server started")
Log to a file as well
Write a log file in your app folder so you can read older history in the file manager:
logging.basicConfig(
level=logging.INFO,
handlers=[logging.StreamHandler(), logging.FileHandler("logs/app.log")],
)
Create the logs folder first. Log files grow forever unless you rotate them, and they count against your disk. Use logging.handlers.RotatingFileHandler in Python, or a rotating transport in Node.js, and cap the size:
from logging.handlers import RotatingFileHandler
handler = RotatingFileHandler("logs/app.log", maxBytes=5_000_000, backupCount=3)
Catch crashes so they get logged
process.on('uncaughtException', (err) => {
console.error('Uncaught exception', err)
process.exit(1)
})
process.on('unhandledRejection', (err) => console.error('Unhandled rejection', err))
Reading a crash
Read the stack trace from the top: the first line is the error, the next lines show where it happened. The first line that points to your own file (rather than node_modules or site-packages) is usually where to look. Common errors are covered in:
When asking for help in the Schokr Discord, paste the full error, not just the last line, and remove any tokens first.