Skip to content

Commit 73a36b5

Browse files
committed
Removed logger / errLogger
1 parent 0f07156 commit 73a36b5

File tree

5 files changed

+27
-23
lines changed

5 files changed

+27
-23
lines changed

lib/handlers/hydrater.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
*/
88

99
var restify = require('restify');
10+
11+
var log = require('../index.js').log;
12+
13+
1014
/**
1115
* This handler receives a document to hydrate on a POST request and processes it.
1216
*
@@ -15,7 +19,7 @@ var restify = require('restify');
1519
* @param {Object} server Current server. See implementation in index.js
1620
* @param {Function} next Callback to call once res has been populated.
1721
*/
18-
module.exports = function(req, res, server, logger, errLogger, next) {
22+
module.exports = function(req, res, server, next) {
1923
if(!req.params.callback) {
2024
return next(new restify.MissingParameterError('No specified callback'));
2125
}
@@ -40,10 +44,10 @@ module.exports = function(req, res, server, logger, errLogger, next) {
4044
var job = server.queue.createJob(task, {priority: task.priority});
4145
job.save(function(err) {
4246
if(err) {
43-
errLogger("Error while queuing: " + ((task.file_path) ? task.file_path : task.document.id) + "\nError :" + err.toString());
47+
log.warn(err, "Error while queuing " + (task.file_path) ? task.file_path : task.document.id);
4448
}
4549
else {
46-
logger("Queuing: " + ((task.file_path) ? task.file_path : task.document.id));
50+
log.info(task, "Queuing task");
4751
}
4852
});
4953

lib/handlers/status.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @param {Object} server Current server. See implementation in index.js
1313
* @param {Function} next Callback to call once res has been populated.
1414
*/
15-
module.exports = function(req, res, server, logger, next) {
15+
module.exports = function(req, res, server, next) {
1616
server.queue.stats(function(err, stats) {
1717
if(err) {
1818
return next(err);

lib/helpers/hydrater.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ var rarity = require('rarity');
1414
var util = require('util');
1515

1616
var lib = require('../index.js');
17+
var log = lib.log;
1718
var HydrationError = lib.HydrationError;
1819
var logError = require('../utils').logError;
1920

2021

2122

22-
module.exports = function(hydraterFunction, childs, logger, errLogger) {
23-
if(!errLogger) {
24-
errLogger = logger;
25-
}
23+
module.exports = function(hydraterFunction, childs) {
24+
2625

2726
/**
2827
* Handle a hydration task:
@@ -36,7 +35,7 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
3635
*/
3736
return function(job, done) {
3837
var task = job.data;
39-
logger("Starting task: " + ((task.file_path) ? task.file_path : task.document.id));
38+
log.info(task, "Starting task");
4039

4140
async.waterfall([
4241
function performHydration(cb) {
@@ -66,10 +65,10 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
6665
cb(err, changes);
6766
}
6867
if(stdout !== "") {
69-
logger(stdout);
68+
log.info({std: "out"}, stdout);
7069
}
7170
if(stderr !== "") {
72-
errLogger(stderr);
71+
log.info({std: "err"}, stderr);
7372
}
7473
clearTimeout(timeout);
7574
};
@@ -139,7 +138,7 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
139138
var changes = {};
140139
changes.hydration_errored = true;
141140
changes.hydration_error = "Task took too long.";
142-
errLogger('Killing task: ' + ((task.file_path) ? task.file_path : task.document.id));
141+
log.warn(task, 'Killing task');
143142
child.process.kill('SIGTERM');
144143
setTimeout(function() {
145144
if(child.process.connected) {
@@ -178,11 +177,11 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
178177
function patchDocument(changes, cb) {
179178
// Returning null means we won't complete the hydration, and are waiting for something else.
180179
if(changes === null) {
181-
logger("Skipped task: " + ((task.file_path) ? task.file_path : task.document.id));
180+
log.info(task, "Skipped task");
182181
return cb();
183182
}
184183

185-
logger("End of task: " + ((task.file_path) ? task.file_path : task.document.id));
184+
log.info(task, "End of task");
186185

187186
var apiUrl = url.parse(task.callback, false, true);
188187

@@ -198,11 +197,11 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
198197
var extra = JSON.parse(JSON.stringify(task));
199198
extra.changes = changes;
200199
logError(err, extra);
201-
errLogger("ERR hydrating " + ((task.file_path) ? task.file_path : task.document.id), err.toString());
200+
log.warn(err, "Unable to hydrate");
202201
}
203202

204203
if(res && res.statusCode && res.statusCode !== 204) {
205-
errLogger("ERR hydrating: server refused data! Code:" + res.statusCode);
204+
log.warn({code: res.statusCode}, "Server refused data!");
206205
}
207206

208207
cb(null);
@@ -228,7 +227,7 @@ module.exports = function(hydraterFunction, childs, logger, errLogger) {
228227
var extra = JSON.parse(JSON.stringify(task));
229228
extra.changes = changes;
230229
logError(internalErr, extra);
231-
errLogger("INTERNAL ERR", internalErr);
230+
log.error(internalErr, "Internal error");
232231
}
233232
done(err || internalErr, changes);
234233
});

lib/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports.log = log;
2626
* hydrater_function, the actual function to use for hydration. This function takes as params the path to the file on the disk, the current data about the document and a callback to use after hydration. First param is the path to the file, second param the document (metadata, binary_document_type). Third param is the callback, send as first argument an error if any, then the new document data.
2727
* Optional:
2828
* concurrency, max number of simultaneous calls to your hydrater function (default is 1)
29+
* opbeat, opbeat credentials
2930
*/
3031
module.exports.createServer = function(config) {
3132
if(!config.hydrater_function) {
@@ -49,7 +50,7 @@ module.exports.createServer = function(config) {
4950

5051
var childs = new Childs(concurrency, tasksPerProcess);
5152

52-
var hydraterHelper = require('./helpers/hydrater.js')(config.hydrater_function, childs, config.logger, config.errLogger);
53+
var hydraterHelper = require('./helpers/hydrater.js')(config.hydrater_function, childs);
5354

5455
var server = restify.createServer({
5556
log: log
@@ -76,10 +77,10 @@ module.exports.createServer = function(config) {
7677
function sigtermYaqs() {
7778
server.yaqsClient.stopAllQueues(function(err) {
7879
if(err) {
79-
config.errLogger(err);
80+
log.warn(err, "Unable to stop queues");
8081
}
8182
childs.stopAllChilds();
82-
config.logger('YAQS has stopped.');
83+
log.info('YAQS has stopped.');
8384
process.exit(0);
8485
});
8586
}
@@ -88,10 +89,10 @@ module.exports.createServer = function(config) {
8889

8990
// Load routes
9091
server.post('/hydrate', function(req, res, next) {
91-
hydraterEndpoint(req, res, server, config.logger, config.errLogger, next);
92+
hydraterEndpoint(req, res, server, next);
9293
});
9394
server.get('/status', function(req, res, next) {
94-
statusEndpoint(req, res, server, config.logger, next);
95+
statusEndpoint(req, res, server, next);
9596
});
9697

9798
// Expose the server

test/cleaning.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ concurrencies.forEach(function(concurrency) {
136136
this.timeout(10000);
137137

138138
var config = {
139-
hydrater_function: path.resolve(__dirname, '../hydraters/erroed-hydrater.js'),
139+
hydrater_function: path.resolve(__dirname, '../hydraters/errored-hydrater.js'),
140140
concurrency: concurrency,
141141
logger: function() {},
142142
};

0 commit comments

Comments
 (0)