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');
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) {
if (err) {
@ -25,7 +25,7 @@ function applyPatch(db, file, callback) {
if (row) {
// 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);
}
@ -39,7 +39,7 @@ function applyPatch(db, file, callback) {
return callback(err);
}
Logger.tag('database', 'migration').info('Patch successfully applied: ' + file);
Logger.tag('database', 'migration').info('Patch successfully applied: %s', file);
callback(null);
});
@ -80,7 +80,7 @@ module.exports = {
var SQLite3 = require('sqlite3');
var file = config.server.databaseFile;
Logger.tag('database').info('Setting up database: ' + file);
Logger.tag('database').info('Setting up database: %s', file);
var db;
try {

View file

@ -12,7 +12,7 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger, confi
var cron = require('node-cron');
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);

View file

@ -23,8 +23,9 @@ angular.module('ffffng')
Logger
.tag('mail', 'queue')
.info(
'Sending pending mail[' + options.id + '] of type ' + options.email + '. ' +
'Had ' + options.failures + ' failures before.'
'Sending pending mail[%d] of type %s. ' +
'Had %d failures before.',
options.id, options.email, options.failures
);
var templateBasePath = __dirname + '/../mailTemplates/' + options.email;
@ -71,7 +72,7 @@ angular.module('ffffng')
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);
});

View file

@ -20,7 +20,7 @@ angular.module('ffffng')
function insertNodeInformation(nodeData, node, callback) {
Logger
.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(
'INSERT INTO node_state ' +
@ -40,18 +40,18 @@ angular.module('ffffng')
function updateNodeInformation(nodeData, node, row, callback) {
Logger
.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)) {
Logger
.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();
}
Logger
.tag('monitoring', 'information-retrieval')
.debug('New data for node, updating:', nodeData.mac);
.debug('New data for node, updating: %s', nodeData.mac);
return Database.run(
'UPDATE node_state ' +
@ -68,7 +68,7 @@ angular.module('ffffng')
function deleteNodeInformation(nodeData, node, callback) {
Logger
.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(
'DELETE FROM node_state WHERE mac = ? AND import_timestamp < ?',
[node.mac, nodeData.importTimestamp.unix()],
@ -78,7 +78,7 @@ angular.module('ffffng')
function storeNodeInformation(nodeData, node, callback) {
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) {
if (err) {
@ -235,7 +235,7 @@ angular.module('ffffng')
retrieveNodeInformation: function (callback) {
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) {
if (err) {
return callback(err);
@ -257,10 +257,8 @@ angular.module('ffffng')
Logger
.tag('monitoring', 'information-retrieval')
.info(
'No new data, skipping.',
'Current timestamp:',
'No new data, skipping. Current timestamp: %s, previous timestamp: %s',
data.importTimestamp.format(),
'Previous timestamp:',
previousImportTimestamp.format()
);
return callback();
@ -270,20 +268,20 @@ angular.module('ffffng')
async.each(
data.nodes,
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) {
if (err) {
Logger
.tag('monitoring', 'information-retrieval')
.error('Error importing:', nodeData.mac, err);
.error('Error importing: ' + nodeData.mac, err);
return nodeCallback(err);
}
if (!node) {
Logger
.tag('monitoring', 'information-retrieval')
.debug('Unknown node, skipping:', nodeData.mac);
.debug('Unknown node, skipping: %s', nodeData.mac);
return nodeCallback(null);
}
@ -291,13 +289,13 @@ angular.module('ffffng')
if (err) {
Logger
.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);
}
Logger
.tag('monitoring', 'information-retrieval')
.debug('Updating / deleting node data done:', nodeData.mac);
.debug('Updating / deleting node data done: %s', nodeData.mac);
nodeCallback();
});

View file

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