Add winston for logging; ignore log files; setInterval still not working.
This commit is contained in:
parent
23c269dc79
commit
e1c49bd4e8
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
node_modules
|
node_modules
|
||||||
db
|
db
|
||||||
|
*.log
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
"handlebars-form-helpers": "^0.1.3",
|
"handlebars-form-helpers": "^0.1.3",
|
||||||
"moment-timezone": "^0.4.0",
|
"moment-timezone": "^0.4.0",
|
||||||
"nodemailer": "^1.3.4",
|
"nodemailer": "^1.3.4",
|
||||||
"sqlite3": "^3.0.8"
|
"sqlite3": "^3.0.8",
|
||||||
|
"winston": "^2.1.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server.js"
|
"start": "node server.js"
|
||||||
|
@ -6,7 +6,8 @@ var courtsopenUtils = require('./courtsopenUtils.js');
|
|||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var bodyParser = require("body-parser");
|
var bodyParser = require("body-parser");
|
||||||
var app = express();
|
var app = express();
|
||||||
var logfile = fs.createWriteStream('./db/log.log', {flags: 'a'});
|
var winston = require('winston');
|
||||||
|
winston.add(winston.transports.File, { filename: 'courtsopen.log' });
|
||||||
|
|
||||||
// Setup email
|
// Setup email
|
||||||
var transporter = nodemailer.createTransport({
|
var transporter = nodemailer.createTransport({
|
||||||
@ -66,6 +67,7 @@ app.set('views', __dirname + '/views');
|
|||||||
app.get('/', function(req, res){
|
app.get('/', function(req, res){
|
||||||
var d = new Date();
|
var d = new Date();
|
||||||
console.log("GET /, " + JSON.stringify(d, 4));
|
console.log("GET /, " + JSON.stringify(d, 4));
|
||||||
|
winston.info("GET /");
|
||||||
var devIndexQry =
|
var devIndexQry =
|
||||||
"select status, published_at " +
|
"select status, published_at " +
|
||||||
"from Alerts " +
|
"from Alerts " +
|
||||||
@ -146,6 +148,8 @@ app.post('/', function(req, res){
|
|||||||
});
|
});
|
||||||
|
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
|
// This log message not appearing!!!
|
||||||
|
winston.debug("this message should appear every minute if setInterval is working.");
|
||||||
// Check every hour to see if GoodMorning or GoodEvening has gone missing.
|
// Check every hour to see if GoodMorning or GoodEvening has gone missing.
|
||||||
var deadManQry = "select published_at from Alerts where datetime(published_at) > datetime('now', '-14.5 hours') order by datetime(published_at) limit 1";
|
var deadManQry = "select published_at from Alerts where datetime(published_at) > datetime('now', '-14.5 hours') order by datetime(published_at) limit 1";
|
||||||
db.get(deadManQry, function(err, row){
|
db.get(deadManQry, function(err, row){
|
||||||
@ -153,6 +157,7 @@ setInterval(function() {
|
|||||||
//else if (typeof row == undefined) {
|
//else if (typeof row == undefined) {
|
||||||
else { // TEST, send the email as long as there's no error.
|
else { // TEST, send the email as long as there's no error.
|
||||||
mailOptions.text = "TEST TEST TEST...It's been too long since the last data transmission from device. \n\n";
|
mailOptions.text = "TEST TEST TEST...It's been too long since the last data transmission from device. \n\n";
|
||||||
|
winston.debug("email body would be: " + mailOptions.text);
|
||||||
|
|
||||||
// Don't include any other details for now, will need to change DB query to get details on last message received.
|
// Don't include any other details for now, will need to change DB query to get details on last message received.
|
||||||
//mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n';
|
//mailOptions.text = mailOptions.text + 'Status message, ' + status + '\n';
|
||||||
@ -171,4 +176,5 @@ setInterval(function() {
|
|||||||
|
|
||||||
app.listen(3000, function() {
|
app.listen(3000, function() {
|
||||||
console.log("Started on PORT 3000");
|
console.log("Started on PORT 3000");
|
||||||
|
winston.info("Started on PORT 3000");
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user