Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created December 17, 2015 13:00
Show Gist options
  • Save indexzero/b8c5d1c9578ce939f52e to your computer and use it in GitHub Desktop.
Save indexzero/b8c5d1c9578ce939f52e to your computer and use it in GitHub Desktop.
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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment