Configure Node.js to log to a file instead of the console

You could also just overload the default console.log function: var fs = require(‘fs’); var util = require(‘util’); var log_file = fs.createWriteStream(__dirname + ‘/debug.log’, {flags : ‘w’}); var log_stdout = process.stdout; console.log = function(d) { // log_file.write(util.format(d) + ‘\n’); log_stdout.write(util.format(d) + ‘\n’); }; Above example will log to debug.log and stdout. Edit: See multiparameter version by … Read more

Why does console.log say undefined, and then the correct value? [duplicate]

The console will print the result of evaluating an expression. The result of evaluating console.log() is undefined since console.log does not explicitly return something. It has the side effect of printing to the console. You can observe the same behaviour with many expressions: > var x = 1; undefined; A variable declaration does not produce … Read more

Why is console.log() considered better than alert()?

alert() is blocking alert() cannot be easily suppressed in non-debug environment console typically formats your objects nicely and allows to traverse them logging statements often have an interactive pointer to code which issued logging statement you cannot look at more than one alert() message at a time consoles can have different logging levels with intuitive … Read more

Google Chrome console.log() inconsistency with objects and arrays

After a lot of digging, I found that this has been reported as a bug, fixed in Webkit, but apparently not yet pulled into Google Chrome. As far as I can tell, the issue was originally reported here: https://bugs.webkit.org/show_bug.cgi?id=35801 : Description From mitch kramer 2010-03-05 11:37:45 PST 1) create an object literal with one or … Read more

JavaScript console.log causes error: “Synchronous XMLHttpRequest on the main thread is deprecated…”

This happened to me when I was being lazy and included a script tag as part of the content that was being returned. As such: Partial HTML Content: <div> SOME CONTENT HERE </div> <script src=”https://stackoverflow.com/scripts/script.js”></script> It appears, at least in my case, that if you return HTML content like that via xhr, you will cause … Read more

What is console.log?

It’s not a jQuery feature but a feature for debugging purposes. You can for instance log something to the console when something happens. For instance: $(‘#someButton’).click(function() { console.log(‘#someButton was clicked’); // do something }); You’d then see #someButton was clicked in Firebug’s “Console” tab (or another tool’s console — e.g. Chrome’s Web Inspector) when you … Read more