var fs = require('fs'); var util = require('util'); var log_file = fs.createWriteStream(__dirname + '/debug.log', {flags: 'w'}); var log2file = function (v) { log_file.write(util.format(v) + '\n'); };
用法
let aa={a:123, b:456}; log2file(aa);
參考:
node.js - Node: log in a file instead of the console - Stack Overflow
沒有留言:
張貼留言