在 Debian 上查看 Node.js 日志,取决于你如何运行 Node.js、是否使用进程管理器(PM2 / systemd)以及项目本身的日志配置。下面按常见场景给你一个完整指南。
ps -ef | grep node
常见情况:
node app.jspm2 list日志直接输出在终端:
node app.js
nohup node app.js > app.log 2>&1 &
查看日志:
tail -f app.log
pm2 logs
查看指定应用:
pm2 logs app-name
实时查看:
pm2 logs --lines 100
ls ~/.pm2/logs/
常见文件:
app-name-out.logapp-name-error.logsystemctl list-units --type=service | grep node
或:
systemctl status your-node-service
journalctl -u your-node-service -f
查看最近 100 行:
journalctl -u your-node-service -n 100
检查服务文件:
cat /etc/systemd/system/your-node-service.service
看是否有:
StandardOutput=append:/var/log/node/app.log
StandardError=append:/var/log/node/error.log
/var/log/node/
/var/log/your-app/
./logs/
查看:
ls -lh /var/log/node
tail -f /var/log/node/app.log
winstonpinomorgan(HTTP 请求)如果 Node 前有 Nginx:
tail -f /var/log/nginx/access.log
tail -f /var/log/nginx/error.log
docker logs container_name
docker logs -f container_name
process.on('uncaughtException', (err) => {
console.error('Uncaught Exception:', err);
});
process.on('unhandledRejection', (err) => {
console.error('Unhandled Rejection:', err);
});
dmesg | tail
journalctl -xe
| 情况 | 查看方式 |
|---|---|
| PM2 | pm2 logs |
| systemd | journalctl -u 服务名 -f |
| 后台 nohup | tail -f app.log |
| Docker | docker logs |
| 项目日志 | /var/log/your-app/ |
| 崩溃 | dmesg / journalctl |
如果你愿意,可以告诉我:
我可以直接给你最精确的查看方式。