Where console.log and print output goes, and how to read your app logs

On your computer, console.log (Node.js) and print (Python) show up on screen. A server has no screen, and the question is where they went. The short answer: on shared hosting, what the application writes goes to the Passenger log, the file you name in the Passenger log file field on the application screen; on a VPS it depends on what starts the application (PM2, systemd or Docker). Without that log, debugging an application is guesswork.

Where the log is, in each case

Where it runs Where to look Command or place
Node.js or Python in cPanel In the file named in the Passenger log file field (on the “Setup Node.js App” or “Setup Python App” screen). Name a file inside the application folder, save, restart and repeat the request. Open it in File Manager, or in Terminal with tail -n 100 file.log.
VPS with PM2 In PM2’s logs. pm2 logs name or pm2 logs --lines 100
VPS with systemd In the system journal. journalctl -u name -n 100, and -f to follow live
Docker In the container’s logs. docker logs name or docker compose logs -f service

The site’s general error log is something else: it catches web server errors, not what your application writes. For that one, see errors 500, 403, 404 and 508.

Making it write logs you can read

1 Set the log file on the application screen (in cPanel), or use PM2’s, systemd’s or Docker’s (on a VPS).
2 Write with meaning. Instead of console.log("here"), say what and with which value: the request’s method and path, the id of the record that was read, the whole error. Never write passwords, keys or personal data.
3 In Python, avoid the delay. When output goes to a file, print may be held in memory and only appear later. Use print("text", flush=True), or the logging module, which writes at once. The environment variable PYTHONUNBUFFERED=1 has the same effect for the whole application.
4 Restart and repeat. Make the request that fails and read the last lines: the cause is usually there. If the application will not even start, see the causes of the 503 error.
A log with no limit ends up filling the disk. On a shared account, a file that grows every day uses space, and space is limited. Delete or archive now and then, or cap the size (in Python, the logging module’s RotatingFileHandler does that). On a VPS, the system journal and Docker’s logs grow too: see Docker filling the disk.
Live, in Terminal. If the account has a terminal (the cPanel Terminal), tail -f file.log shows lines as they arrive: open the site in another tab and watch what appears. To leave, Ctrl+C.

Have the log in front of you and cannot make sense of the last line? Send us the domain, the time of the error and that line.

Open a support ticket

SEE ALSO

Node.js app in cPanel returns 503: the usual causes

Website errors explained: 500, 403, 404, 508 and what to do

The cPanel Terminal: a command line with nothing to install

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from £5.28/mo (3-year plan, with coupon)

See plans
  • 0 Users Found This Useful
Was this answer helpful?