通過 Debian Node.js 日志排查問題可按以下步驟操作:
查看應用日志
error.log
、combined.log
),用 tail -f
實時監控或 grep
篩選關鍵信息(如 ERROR
)。console.log
或基礎日志文件定位問題。檢查系統日志
journalctl -u your-nodejs-service
查看服務相關日志(需先配置為 systemd 服務)。/var/log/syslog
或 /var/log/messages
,搜索 node
相關條目。分析日志內容
morgan
中間件記錄),排查接口異常。使用調試工具
node --inspect-brk app.js
啟動調試模式,配合 Chrome DevTools 或 VS Code 逐步執行代碼。監控與優化
winston-daily-rotate-file
)避免文件過大。關鍵命令示例:
tail -f app.log
或 journalctl -u nodeapp -f
grep "ERROR" app.log
node --inspect-brk server.js
通過以上方法可快速定位 Debian 環境下 Node.js 應用的日志問題。