在 Debian 系统上,JavaScript(JS)日志缺失通常不是单一原因,而是环境、配置、权限或代码层面多种因素叠加。下面按常见场景系统梳理原因及排查思路。
console.log 被注释 / 被 tree-shaking 移除(生产构建)error,但写的是 debug)if (DEBUG) 未开启)✅ 排查:
console.log('test log')
直接运行确认是否输出。
node app.js > /dev/null 2>&1 &
pm2 / systemd 但未配置日志✅ 排查:
ps aux | grep node
查看是否有重定向。
✅ 检查:
pm2 logs
pm2 describe <id>
JS 应用直接 console.log,但未通过 systemd 启动。
✅ 正确方式:
[Service]
ExecStart=/usr/bin/node /opt/app/app.js
StandardOutput=journal
StandardError=journal
查看日志:
journalctl -u your-service -f
✅ 检查:
journalctl --disk-usage
配置:
/etc/systemd/journald.conf
www-data / node 用户✅ 排查:
ls -ld /var/log/yourapp
touch /var/log/yourapp/test
window.onerror = () => true
常见问题:
✅ 示例(winston):
transports: [new winston.transports.File({ filename: '/var/log/app.log' })]
df -h
df -i
timedatectl
# 1. 进程是否存在
ps aux | grep node
# 2. 是否有重定向
cat /proc/<pid>/fd/1
# 3. systemd 日志
journalctl -u your-service -n 50
# 4. 文件权限
ls -l /var/log/yourapp
# 5. 磁盘状态
df -h && df -i
如果你能补充以下信息,我可以更精准定位:
我可以直接给你对应修复方案。