Why is casper.logs property is undefined ?

27 views
Skip to first unread message

Naomi Kyoto

unread,
Jul 13, 2015, 7:34:39 PM7/13/15
to casp...@googlegroups.com

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

Gabe Misura

unread,
Jul 15, 2015, 11:58:23 AM7/15/15
to casp...@googlegroups.com
this.log spits to STDOUT. I'm not sure it will go to a file the way you think.

I also have verbose:true

var casper = require('casper').create( { verbose: true, logLevel: 'debug' });
Reply all
Reply to author
Forward
0 new messages