在 Debian 系统中定位 Node.js 日志,取决于日志是写到哪里的。下面按常见场景给你一份实用排查清单。
如果 Node.js 直接用 console.log / console.error:
前台运行
node app.js
日志直接输出到终端。
后台运行(systemd / nohup / pm2) 日志会被重定向到:
systemctl list-units --type=service | grep node
journalctl -u your-node-service.service -f
journalctl -u your-node-service.service --since "2025-01-01" --until "2025-01-10"
systemctl cat your-node-service.service
常见配置:
StandardOutput=journal
StandardError=journal
或:
StandardOutput=append:/var/log/node/app.log
StandardError=append:/var/log/node/error.log
pm2 logs
只看某个应用:
pm2 logs app-name
~/.pm2/logs/
例如:
app-name-out.log
app-name-error.log
pm2 show app-name
nohup node app.js &
日志在:
nohup.out
node app.js > /var/log/node/app.log 2>&1
find /var/log -name "*.log" 2>/dev/null
find /home -name "*.log" 2>/dev/null
// 示例:winston
new winston.transports.File({ filename: '/var/log/node/app.log' })
grep -R "logs" /path/to/project
/var/log/nginx/access.log
/var/log/nginx/error.log
✅ 如果是 systemd
journalctl -u 服务名 -f
✅ 如果是 PM2
pm2 logs
✅ 如果是直接运行
ps aux | grep node
ls -l /proc/<pid>/fd
✅ 全局搜索日志
find / -name "*.log" 2>/dev/null | grep node
你可以直接贴出:
ps aux | grep node 输出我可以精确告诉你是哪一行配置决定了日志位置。