在 Ubuntu 上查找 Node.js 日志,取决于你的运行方式(直接运行、PM2、systemd、Docker 等)。下面按常见场景给你总结:
如果你是这样运行的:
node app.js
日志直接在终端显示。
如果是后台运行:
node app.js > app.log 2>&1 &
查看日志:
tail -f app.log
nohup node app.js &
默认日志在:
nohup.out
查看:
tail -f nohup.out
pm2 logs
查看某个应用:
pm2 logs appname
~/.pm2/logs/
例如:
~/.pm2/logs/appname-out.log
~/.pm2/logs/appname-error.log
如果 Node.js 是系统服务:
journalctl -u your-node-service
实时查看:
journalctl -u your-node-service -f
systemctl list-units --type=service | grep node
docker logs container_name
实时查看:
docker logs -f container_name
/var/log/syslog
/var/log/messages
搜索 node 相关:
grep node /var/log/syslog
ps aux | grep node
lsof -i :3000
netstat -tunlp | grep node
如果你能告诉我:
我可以给你更精确的命令。