Skip to content

Instantly share code, notes, and snippets.

@nilasissen
Created July 3, 2017 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilasissen/0d370626ee9624a4731a1e391e48d7eb to your computer and use it in GitHub Desktop.
Save nilasissen/0d370626ee9624a4731a1e391e48d7eb to your computer and use it in GitHub Desktop.
create logger using console.log Nodejs
var logFile = fs.createWriteStream(__dirname + config.logPath + new Date().toISOString().slice(0, 19).replace('T', ' '), {
flags: 'a'
});
var logStdout = process.stdout;
var baseUrl = config.baseUrl;
console.log = function () {
logFile.write(
"\n===:" + new Date() + ":\n" +
util.format.apply(null, arguments) +
'\n===\n'
);
logStdout.write(
"\n===:" + new Date() + ":\n" +
util.format.apply(null, arguments) +
'\n===\n'
);
}
console.error = console.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment