Commit cbc01fc3 cbc01fc3001440d353dd2216a449051174df768f by Nicolas Perriault

added docstrings to the customlogging.js sample

1 parent e429daff
1 /**
2 * A basic custom logging implementation. The idea is to (extremely) verbosely
3 * log every received resource.
4 *
5 */
1 phantom.injectJs('casper.js'); 6 phantom.injectJs('casper.js');
2 7
3 var casper = new phantom.Casper({ 8 var casper = new phantom.Casper({
9 /**
10 * Every time a resource is received, a new log entry is added to the stack
11 * at the 'verbose' level.
12 *
13 * @param Object resource A phantomjs resource object
14 */
4 onResourceReceived: function(self, resource) { 15 onResourceReceived: function(self, resource) {
5 var infos = [ 16 var infos = [
6 resource.url, 17 resource.url,
...@@ -14,12 +25,14 @@ var casper = new phantom.Casper({ ...@@ -14,12 +25,14 @@ var casper = new phantom.Casper({
14 }); 25 });
15 self.log(infos.join(', '), 'verbose'); 26 self.log(infos.join(', '), 'verbose');
16 }, 27 },
17 verbose: true, 28 verbose: true, // we want to see the log printed out to the console
18 logLevel: 'verbose' 29 logLevel: 'verbose' // of course we want to see logs to our new level :)
19 }); 30 });
20 31
32 // add a new 'verbose' logging level at the lowest priority
21 casper.logLevels = ['verbose'].concat(casper.logLevels); 33 casper.logLevels = ['verbose'].concat(casper.logLevels);
22 34
35 // test our new logger with google
23 casper.start('http://www.google.com/').run(function(self) { 36 casper.start('http://www.google.com/').run(function(self) {
24 self.exit(); 37 self.exit();
25 }); 38 });
......