From PhantomJS, how do I write to a log instead of to the console?
In the examples https://github.com/ariya/phantomjs/wiki/Examples, it always (in the ones I have looked at) says something like:
console.log('some stuff I wrote');
This is not so useful.
The following can write contents to the file directly by phantomjs:
The command in the answer by user984003 fails when there is some warning or exceptions occurred. And sometimes does not fall into our specific requirements because in some codebase I am getting the following message always which will also be logged to that file.
You can override original console.log function, take a look at this :
Then you can do this:
So I figured it out: