diff --git a/browser/atom/atom.coffee b/browser/atom/atom.coffee index bbc6c617883d..6385a01f9550 100644 --- a/browser/atom/atom.coffee +++ b/browser/atom/atom.coffee @@ -1,6 +1,12 @@ fs = require 'fs' path = require 'path' +# Redirect node's console to use our own implementations, since node can not +# handle output when running as GUI program. +if process.platform is 'win32' + console.log = console.error = console.warn = process.log + process.stdout.write = process.stderr.write = process.log + # Enable idle gc. process.atomBinding('idle_gc').start() diff --git a/common/api/atom_bindings.cc b/common/api/atom_bindings.cc index ca9f09f63834..1f478c127de0 100644 --- a/common/api/atom_bindings.cc +++ b/common/api/atom_bindings.cc @@ -35,6 +35,7 @@ void AtomBindings::BindTo(v8::Handle process) { node::SetMethod(process, "atomBinding", Binding); node::SetMethod(process, "crash", Crash); node::SetMethod(process, "activateUvLoop", ActivateUVLoop); + node::SetMethod(process, "log", Log); } // static @@ -96,4 +97,14 @@ v8::Handle AtomBindings::ActivateUVLoop(const v8::Arguments& args) { return v8::Undefined(); } +// static +v8::Handle AtomBindings::Log(const v8::Arguments& args) { + std::string message; + for (int i = 0; i < args.Length(); ++i) + message += *v8::String::Utf8Value(args[i]); + + logging::LogMessage("CONSOLE", 0, 0).stream() << message; + return v8::Undefined(); +} + } // namespace atom diff --git a/common/api/atom_bindings.h b/common/api/atom_bindings.h index 8280b7760945..31b0152f047a 100644 --- a/common/api/atom_bindings.h +++ b/common/api/atom_bindings.h @@ -23,6 +23,7 @@ class AtomBindings { static v8::Handle Binding(const v8::Arguments& args); static v8::Handle Crash(const v8::Arguments& args); static v8::Handle ActivateUVLoop(const v8::Arguments& args); + static v8::Handle Log(const v8::Arguments& args); DISALLOW_COPY_AND_ASSIGN(AtomBindings); };