Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Stub out console.log format strings, info, warn, error

  • Loading branch information...
commit c9e12204a20ab14b57b5811479a1f1a031f12b5b 1 parent 23172c5
@ry ry authored
Showing with 29 additions and 3 deletions.
  1. +29 −3 src/node.js
View
32 src/node.js
@@ -29,10 +29,12 @@ process.assert = function (x, msg) {
if (!x) throw new Error(msg || "assertion error");
};
+var writeError = process.binding('stdio').writeError;
+
var evalcxMsg;
process.evalcx = function () {
if (!evalcxMsg) {
- process.binding('stdio').writeError(evalcxMsg =
+ writeError(evalcxMsg =
"process.evalcx is deprecated. Use Script.runInNewContext instead.\n");
}
return process.binding('evals').Script
@@ -187,12 +189,36 @@ process.openStdin = function () {
};
+// console object
+
+function format (f) {
+ var i = 1;
+ var args = arguments;
+ return f.replace(/%([sdf])/g, function (x) {
+ switch (x) {
+ case '%s': return args[i++];
+ case '%d': return args[i++].toString();
+ case '%f': return JSON.stringify(args[i++]);
+ default:
+ return x;
+ }
+ });
+}
+
global.console = {};
-global.console.log = function (x) {
- process.stdout.write(x + '\n');
+global.console.log = function () {
+ process.stdout.write(format.apply(this, arguments) + '\n');
};
+global.console.info = global.console.log;
+
+global.console.warn = function () {
+ writeError(format.apply(this, arguments) + '\n');
+};
+
+global.console.error = global.console.warn;
+
process.exit = function (code) {
process.emit("exit");

1 comment on commit c9e1220

@pixelspark

Perhaps add a fast path here that just calls process.stdout.write when only a single argument is given to log/info/error?

Please sign in to comment.
Something went wrong with that request. Please try again.