Welcome, guest | Sign In | My Account | Store | Cart

I tend to have a "quicklog" method for a few of the languages I'm working in to do logging when stdout/stderr isn't necessarily available (GUI app) or convenient (lots of other output on stdout, etc.). My usage with nodejs was while working on the node REPL. Log output to stdout interfered with the REPL.

JavaScript, 8 lines
1
2
3
4
5
6
7
8
function quicklog(s) {
  var logpath = "/tmp/quick.log";
  var fs = require('fs');
  s = s.toString().replace(/\r\n|\r/g, '\n'); // hack
  var fd = fs.openSync(logpath, 'a+', 0666);
  fs.writeSync(fd, s + '\n');
  fs.closeSync(fd);
}
Created by Trent Mick on Wed, 11 Aug 2010 (MIT)
JavaScript recipes (69)
Trent Mick's recipes (28)

Required Modules

  • (none specified)

Other Information and Tasks