From 13290ce222982b38d3d0fcc3ea688b7a7ec01605 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 13 Nov 2018 08:32:37 +0000 Subject: [PATCH] AppendFileSync and like shit --- down-detector.js | 9 +++++---- logs.log | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/down-detector.js b/down-detector.js index 660531f..17536f9 100644 --- a/down-detector.js +++ b/down-detector.js @@ -3,6 +3,7 @@ const fs = require('fs'); const moment = require('moment'); setInterval(doStuff, 1000); +fs.appendFileSync('logs.log', 'NEW SESSION\n'); let lastState; let connected; @@ -15,7 +16,7 @@ function doStuff() { timeout: 10 }).then((result) => { connected = result.alive; - //log(connected); + if (lastState == true && connected == false) { LostConnection(); @@ -39,17 +40,17 @@ const dateFormat = 'DD-MM-YY HH:MM:ss'; function ConnectionRegained(timedown) { let output = '[' + moment().format(dateFormat) + '] Connection regained after ' + timedown + 's of downtime'; console.log(output); - fs.writeFileSync('logs.log', output + '\n'); + fs.appendFileSync('logs.log', output + '\n'); } function LostConnection() { let output = '[' + moment().format(dateFormat) + '] Lost Connection'; console.log(output); - fs.writeFileSync('logs.log', output + '\n'); + fs.appendFileSync('logs.log', output + '\n'); } function log(tolog) { let output = '[' + moment().format(dateFormat) + '] ' + tolog; console.log(output); - fs.writeFileSync('logs.log', output + '\n'); + fs.appendFileSync('logs.log', output + '\n'); } diff --git a/logs.log b/logs.log index 990f60f..da63d78 100644 --- a/logs.log +++ b/logs.log @@ -1 +1,2 @@ -[22:21:47] Connection regained after 40s of downtime +[13-11-18 07:11:34] Connection regained after 41s of downtime +NEW SESSIONNEW SESSION