casperjs version: 1.1.0-beta3
phantomjs version: 1.9.8
var casper = require('casper').create(); casper.start("http://google.com", function() { this.log('loaded google!'); }); casper.then(function() { this.log('this is a debug message', 'debug'); this.log('and an informative one', 'info'); this.log('and a warning', 'warning'); this.log('and an error', 'error'); }); casper.run(function() { require('utils').dump(this.logs); this.exit(); });
Run it
$ casperjs myscript.js undefined
As you can see, this.logs
is undefined
. According to the logging docs, the logs
property should collect the log messages during script execution.
Paste from the docs:
You can also dump a JSON log of your Casper suite just by rendering the contents of the Casper.logs property:
var casper = require('casper').create({ // ... casper.run(function() { require('utils').dump(this.logs); this.exit(); });
My end goal is to do something like
casper.run(function() { fs.write('./report.log', JSON.stringify(this.logs, null, "\t"), 'w'); // ... });
I've also tried to initialize casper with various options
var casper = require('casper').create({logLevel: 'info'}); // ...
But no matter what I try, this.logs
is undefined. Can someone please help?
Original post at: https://github.com/n1k0/casperjs/issues/1269