diff --git a/deps/node/lib/internal/bootstrap/switches/is_main_thread.js b/deps/node/lib/internal/bootstrap/switches/is_main_thread.js index b64b362e15..27a694c444 100644 --- a/deps/node/lib/internal/bootstrap/switches/is_main_thread.js +++ b/deps/node/lib/internal/bootstrap/switches/is_main_thread.js @@ -49,7 +49,7 @@ function createWritableStdioStream(fd) { const { Writable } = require('stream'); stream = new Writable({ write(chunk, encoding, callback) { - process.lwnode._print(chunk.toString()); + process.lwnode._print(chunk.toString(), this.fd); callback(); } }); diff --git a/deps/node/src/node_process_methods.cc b/deps/node/src/node_process_methods.cc index 72ea3fed9e..f8f7f79495 100644 --- a/deps/node/src/node_process_methods.cc +++ b/deps/node/src/node_process_methods.cc @@ -29,6 +29,8 @@ typedef int mode_t; #include // tcgetattr, tcsetattr #endif +#include "trace.h" // @lwnode + namespace node { using v8::Array; @@ -436,10 +438,19 @@ static void ReallyExit(const FunctionCallbackInfo& args) { } void Logger(const FunctionCallbackInfo& args) { - CHECK(args.Length() == 1 && args[0]->IsString() && + CHECK(args.Length() > 0 && args[0]->IsString() && "must be called with a single string"); Utf8Value message(args.GetIsolate(), args[0]); - FPrintF(stderr, "%s", message); + + Environment* env = Environment::GetCurrent(args); + + if (args.Length() > 1 && args[1]->IsInt32() && + args[1]->Int32Value(env->context()).FromJust() == 2) { + // stderr + LWNODE_DEV_FATAL_LOG(message.ToString().c_str()); + } else { + FPrintF(stderr, "%s", message); + } } static void InitializeProcessMethods(Local target,