howto disable stack trace for console output of fprintf

52 views
Skip to first unread message

juergen...@gmail.com

unread,
Aug 11, 2023, 7:27:53 AM8/11/23
to emscripten-discuss
I sometimes just want to print trace output from the C/C++ side and I do not care about the stack trace info in that scenario. I already do know exactly where the messages come from and the stack unnecessarily bloats the output by 1-2 orders of magnitude - sometimes slowing the browser to a crawl due to the amount of data, and unnecessarily complicating the actual use of the log data..

How can EMSCRIPTEN's default impl of always including the stack info be overridden to just print my plain fprint messages?

Mike Lischke

unread,
Aug 11, 2023, 8:15:43 AM8/11/23
to emscripte...@googlegroups.com

I sometimes just want to print trace output from the C/C++ side and I do not care about the stack trace info in that scenario. I already do know exactly where the messages come from and the stack unnecessarily bloats the output by 1-2 orders of magnitude - sometimes slowing the browser to a crawl due to the amount of data, and unnecessarily complicating the actual use of the log data..

How can EMSCRIPTEN's default impl of always including the stack info be overridden to just print my plain fprint messages?

Instead of printf use std::cout << "your message" << yourObject << std::endl, if you are in C++. That only prints that message, nothing else (and does good formatting). I use that currently for debugging.


Message has been deleted
Message has been deleted

juergen...@gmail.com

unread,
Aug 11, 2023, 8:56:26 AM8/11/23
to emscripten-discuss
Thanks for the tip. The behavior actually seems to depend on std::cerr/stderr.. when stdout is used instead then the stacktrace is gone (i.e. works also in C).

To then also get rid of the annoying "source file" info console.log has to be replaced before the EMSCRIPTEN Module is instanciated, i.e. putting something like the below into the respective file does the trick (and it doesn't seem to have any negative effects on the scenarios where you actually want to log an error with stacktrace):

let origLog = console.log;
console.log = function(t) {
setTimeout(origLog.bind(console, t)); // "lose" the original context
};

problem solved :-)

juergen...@gmail.com

unread,
Aug 11, 2023, 10:27:11 AM8/11/23
to emscripten-discuss
PS: the above globally changes the console's behavior and has the side effect that log calls made from unrelated JavaScript code will also no longer show the "source file". The clean way is probably to define the Module's "print" function by passing a respective object into the Module constuction function:

let in = {
print: function(t) {
// suppress annoying "source file" info
setTimeout(console.log.bind(console, t)); // "lose" the original context
}
};
Reply all
Reply to author
Forward
0 new messages