code: function hook_stdout(callback) {
          var old_write;
          var useProcess;
          if(typeof(process)!=="undefined") {
              old_write = process.stdout.write;
              useProcess = true;
              process.stdout.write = (function(write) {
                  return function(string, encoding, fd) {
                      write.apply(process.stdout, arguments);
                      callback(string, encoding, fd);
                  };
              })(old_write);
          }
          else {
              old_write = console.log.bind(console);
              useProcess = false;
              console.log = (function(write) {
                  return function(string) {
                      write.apply(string);
                      callback(string, "utf8");
                  };
              })(old_write);
          }
          return function() {
              if(useProcess) {
                  process.stdout.write = old_write;
              }
              else {
                  console.log = old_write;
              }
          };
      }
docs: Hooks into either process.stdout (node) or console.log, if that is not
  available (see https://gist.github.com/pguillory/729616).