在 Debian 上“导出 JS 日志”通常指把 Node.js 应用日志 或 前端 JS 在浏览器里的日志 保存出来。下面按常见场景说明。
node app.js > app.log 2>&1
>:标准输出2>&1:错误也写入pm2 logs app --out logs/app.out.log --err logs/app.err.log
或导出历史日志:
pm2 flush
pm2 logs --raw > all.log
如果是 systemd 管理的 Node 服务:
journalctl -u your-node-service.service -e > node.log
实时导出:
journalctl -u your-node-service.service -f
const fs = require('fs');
console.log = (msg) => {
fs.appendFileSync('app.log', `${new Date()} ${msg}\n`);
};
如果是前端 JS 报错通过接口上报:
tail -f /var/log/nginx/access.log > js_access.log
浏览器按 F12 → Console → 右键 → Save as…
const logs = [];
console.log = (...args) => logs.push(args.join(' '));
function downloadLog() {
const blob = new Blob([logs.join('\n')], {type:'text/plain'});
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'js.log';
a.click();
}
docker logs container_name > js.log 2>&1
如果你能说清楚:
我可以给你更精确的命令。