Created
December 17, 2015 13:00
-
-
Save indexzero/b8c5d1c9578ce939f52e to your computer and use it in GitHub Desktop.
Fun with hacking console.log in node@4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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