Homemade Automatic Domain Tester with PhantomJS Part 3

Previously on Bitpi

If you have stumbled across this post and haven't read the previous posts, check them out. Also, the code can be found here.

Previously, we built a domain tester than tested all the sites that we included in our array. Then we hooked it up to cron job to run on a schedule. Now we need to give our program some sort of output show we know how the testing is going.

Tools within My Reach

Things to do this time around

Create an output 'log.txt' text file.

Let's edit domain_tester.js

Open your domain_tester.js file in a text editor.

nano domain_tester.js

We'll need to declare some new variables at the beginning of the program. 'fs' is for the file system module in PhantomJS. 'log.txt' is going to be our output file.

var fs = require('fs');
var path = 'log.txt';

At the end of the program we need to state what we want to write to the log.txt file. Some good ideas might be to include:

So we'll include the following..

var logcontent = [
    mydate + " ",
    timeInSecs + " seconds of runtime",
    Prodsites.length + " domains",
    successes + " total successes",
    failures + " total failures",
    ];

Now we have to use the write method to update the file. The 'a' tells it to append (add to) the file instead of overwriting what may already be in the file, which would be 'w'. Since we want to run this program over and over, we don't want to overwrite any information.

So before the program exits PhantomJS, lets add this line..

fs.write(path, logcontent, 'a');

Notice we inluded 'logcontent', the array with all the stuff we want listed in our file.

Now when our domain tester runs, it will keep a log of what happens! Even while we are nestled in our beds!

View of the log file after the program runs