indexzero
12/17/2015 - 1:00 PM

Fun with hacking console.log in node@4

Fun with hacking console.log in node@4

'use strict';

//
// Attempt #1: Overwrite the log method on the Console
// prototype exposed by node.
//
// !!FAILED!!
//
// var Console = require('console').Console;
//
// var _log = Console.prototype.log;
// Console.prototype.log = function () {
//   process.stdout.write('wtf');
//   // Do whatever you want here
//   _log.apply(this, arguments);
// }
//
// process.stdout.write(console.log.toString());
// console.log('hi');
//

//
// Attempt #2: Overwrite process.stdout.write.
//
var _write = process.stdout.write;
process.stdout.write = function () {
  process.stderr.write('wtf');
  _write.apply(process.stdout, arguments);
};

console.log('hi');