More consistent logging

This commit is contained in:
baldo 2016-05-24 21:08:34 +02:00
parent e03be8bf51
commit 0ccab4cac8
5 changed files with 29 additions and 29 deletions

View file

@ -9,7 +9,7 @@ var config = require('../config');
var Logger = require('../logger'); var Logger = require('../logger');
function applyPatch(db, file, callback) { function applyPatch(db, file, callback) {
Logger.tag('database', 'migration').info('Checking if patch need to be applied: ' + file); Logger.tag('database', 'migration').info('Checking if patch need to be applied: %s', file);
fs.readFile(file, function (err, contents) { fs.readFile(file, function (err, contents) {
if (err) { if (err) {
@ -25,7 +25,7 @@ function applyPatch(db, file, callback) {
if (row) { if (row) {
// patch is already applied. skip! // patch is already applied. skip!
Logger.tag('database', 'migration').info('Patch already applied, skipping: ' + file); Logger.tag('database', 'migration').info('Patch already applied, skipping: %s', file);
return callback(null); return callback(null);
} }
@ -39,7 +39,7 @@ function applyPatch(db, file, callback) {
return callback(err); return callback(err);
} }
Logger.tag('database', 'migration').info('Patch successfully applied: ' + file); Logger.tag('database', 'migration').info('Patch successfully applied: %s', file);
callback(null); callback(null);
}); });
@ -80,7 +80,7 @@ module.exports = {
var SQLite3 = require('sqlite3'); var SQLite3 = require('sqlite3');
var file = config.server.databaseFile; var file = config.server.databaseFile;
Logger.tag('database').info('Setting up database: ' + file); Logger.tag('database').info('Setting up database: %s', file);
var db; var db;
try { try {

View file

@ -12,7 +12,7 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
var cron = require('node-cron'); var cron = require('node-cron');
function schedule(expr, jobName) { function schedule(expr, jobName) {
Logger.tag('jobs').info('Scheduling job: ' + expr + ' ' + jobName); Logger.tag('jobs').info('Scheduling job: %s %s', expr, jobName);
var job = $injector.get(jobName); var job = $injector.get(jobName);

View file

@ -23,8 +23,9 @@ angular.module('ffffng')
Logger Logger
.tag('mail', 'queue') .tag('mail', 'queue')
.info( .info(
'Sending pending mail[' + options.id + '] of type ' + options.email + '. ' + 'Sending pending mail[%d] of type %s. ' +
'Had ' + options.failures + ' failures before.' 'Had %d failures before.',
options.id, options.email, options.failures
); );
var templateBasePath = __dirname + '/../mailTemplates/' + options.email; var templateBasePath = __dirname + '/../mailTemplates/' + options.email;
@ -71,7 +72,7 @@ angular.module('ffffng')
return callback(err); return callback(err);
} }
Logger.tag('mail', 'queue').info('Mail[' + options.id +'] has been send.'); Logger.tag('mail', 'queue').info('Mail[%d] has been send.', options.id);
callback(null); callback(null);
}); });

View file

@ -20,7 +20,7 @@ angular.module('ffffng')
function insertNodeInformation(nodeData, node, callback) { function insertNodeInformation(nodeData, node, callback) {
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('Node is new in monitoring, creating data:', nodeData.mac); .debug('Node is new in monitoring, creating data: %s', nodeData.mac);
return Database.run( return Database.run(
'INSERT INTO node_state ' + 'INSERT INTO node_state ' +
@ -40,18 +40,18 @@ angular.module('ffffng')
function updateNodeInformation(nodeData, node, row, callback) { function updateNodeInformation(nodeData, node, row, callback) {
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('Node is known in monitoring:', nodeData.mac); .debug('Node is known in monitoring: %s', nodeData.mac);
if (!moment(row.import_timestamp).isBefore(nodeData.importTimestamp)) { if (!moment(row.import_timestamp).isBefore(nodeData.importTimestamp)) {
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('No new data for node, skipping:', nodeData.mac); .debug('No new data for node, skipping: %s', nodeData.mac);
return callback(); return callback();
} }
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('New data for node, updating:', nodeData.mac); .debug('New data for node, updating: %s', nodeData.mac);
return Database.run( return Database.run(
'UPDATE node_state ' + 'UPDATE node_state ' +
@ -68,7 +68,7 @@ angular.module('ffffng')
function deleteNodeInformation(nodeData, node, callback) { function deleteNodeInformation(nodeData, node, callback) {
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('Node is not being monitored, deleting monitoring data:', nodeData.mac); .debug('Node is not being monitored, deleting monitoring data: %s', nodeData.mac);
return Database.run( return Database.run(
'DELETE FROM node_state WHERE mac = ? AND import_timestamp < ?', 'DELETE FROM node_state WHERE mac = ? AND import_timestamp < ?',
[node.mac, nodeData.importTimestamp.unix()], [node.mac, nodeData.importTimestamp.unix()],
@ -78,7 +78,7 @@ angular.module('ffffng')
function storeNodeInformation(nodeData, node, callback) { function storeNodeInformation(nodeData, node, callback) {
if (node.monitoring && node.monitoringConfirmed) { if (node.monitoring && node.monitoringConfirmed) {
Logger.tag('monitoring', 'information-retrieval').debug('Node is being monitored:', nodeData.mac); Logger.tag('monitoring', 'information-retrieval').debug('Node is being monitored: %s', nodeData.mac);
return Database.get('SELECT * FROM node_state WHERE mac = ?', [node.mac], function (err, row) { return Database.get('SELECT * FROM node_state WHERE mac = ?', [node.mac], function (err, row) {
if (err) { if (err) {
@ -235,7 +235,7 @@ angular.module('ffffng')
retrieveNodeInformation: function (callback) { retrieveNodeInformation: function (callback) {
var url = config.server.map.nodesJsonUrl; var url = config.server.map.nodesJsonUrl;
Logger.tag('monitoring', 'information-retrieval').info('Retrieving nodes.json:', url); Logger.tag('monitoring', 'information-retrieval').info('Retrieving nodes.json: %s', url);
request(url, function (err, response, body) { request(url, function (err, response, body) {
if (err) { if (err) {
return callback(err); return callback(err);
@ -257,10 +257,8 @@ angular.module('ffffng')
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.info( .info(
'No new data, skipping.', 'No new data, skipping. Current timestamp: %s, previous timestamp: %s',
'Current timestamp:',
data.importTimestamp.format(), data.importTimestamp.format(),
'Previous timestamp:',
previousImportTimestamp.format() previousImportTimestamp.format()
); );
return callback(); return callback();
@ -270,20 +268,20 @@ angular.module('ffffng')
async.each( async.each(
data.nodes, data.nodes,
function (nodeData, nodeCallback) { function (nodeData, nodeCallback) {
Logger.tag('monitoring', 'information-retrieval').debug('Importing:', nodeData.mac); Logger.tag('monitoring', 'information-retrieval').debug('Importing: %s', nodeData.mac);
NodeService.findNodeDataByMac(nodeData.mac, function (err, node) { NodeService.findNodeDataByMac(nodeData.mac, function (err, node) {
if (err) { if (err) {
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.error('Error importing:', nodeData.mac, err); .error('Error importing: ' + nodeData.mac, err);
return nodeCallback(err); return nodeCallback(err);
} }
if (!node) { if (!node) {
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('Unknown node, skipping:', nodeData.mac); .debug('Unknown node, skipping: %s', nodeData.mac);
return nodeCallback(null); return nodeCallback(null);
} }
@ -291,13 +289,13 @@ angular.module('ffffng')
if (err) { if (err) {
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('Could not update / deleting node data: ', nodeData.mac, err); .debug('Could not update / deleting node data: %s', nodeData.mac, err);
return nodeCallback(err); return nodeCallback(err);
} }
Logger Logger
.tag('monitoring', 'information-retrieval') .tag('monitoring', 'information-retrieval')
.debug('Updating / deleting node data done:', nodeData.mac); .debug('Updating / deleting node data done: %s', nodeData.mac);
nodeCallback(); nodeCallback();
}); });

View file

@ -7,6 +7,7 @@ angular.module('ffffng')
crypto, crypto,
fs, fs,
glob, glob,
Logger,
MailService, MailService,
Strings, Strings,
ErrorTypes, ErrorTypes,
@ -141,12 +142,12 @@ angular.module('ffffng')
return callback(error); return callback(error);
} }
var file = files[0];
try { try {
var file = files[0];
fs.unlinkSync(file); fs.unlinkSync(file);
} }
catch (error) { catch (error) {
console.error(error); Logger.tag('node', 'save').error('Could not delete old node file: ' + file, error);
return callback({data: 'Could not remove old node data.', type: ErrorTypes.internalError}); return callback({data: 'Could not remove old node data.', type: ErrorTypes.internalError});
} }
} else { } else {
@ -160,7 +161,7 @@ angular.module('ffffng')
fs.writeFileSync(filename, data, 'utf8'); fs.writeFileSync(filename, data, 'utf8');
} }
catch (error) { catch (error) {
console.error(error); Logger.tag('node', 'save').error('Could not write node file: ' + filename, error);
return callback({data: 'Could not write node data.', type: ErrorTypes.internalError}); return callback({data: 'Could not write node data.', type: ErrorTypes.internalError});
} }
@ -177,7 +178,7 @@ angular.module('ffffng')
fs.unlinkSync(files[0]); fs.unlinkSync(files[0]);
} }
catch (error) { catch (error) {
console.error(error); Logger.tag('node', 'delete').error('Could not delete node file: ' + file, error);
return callback({data: 'Could not delete node.', type: ErrorTypes.internalError}); return callback({data: 'Could not delete node.', type: ErrorTypes.internalError});
} }
@ -263,8 +264,8 @@ angular.module('ffffng')
disableUrl: disableUrl disableUrl: disableUrl
}, },
function (err) { function (err) {
if (err) {checkNoDuplicates if (err) {
console.error(err); Logger.tag('monitoring', 'confirmation').error('Could not enqueue confirmation mail.', error);
return callback({data: 'Internal error.', type: ErrorTypes.internalError}); return callback({data: 'Internal error.', type: ErrorTypes.internalError});
} }