Skip to content

Commit 6b0ed1c

Browse files
author
Hugo Duroux
committed
Merge pull request #43 from AnyFetch/improved-logging
Log less data for tasks
2 parents 09fd368 + 110fdae commit 6b0ed1c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/helpers/hydrater.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ var HydrationError = lib.HydrationError;
1919
var logError = require('../utils').logError;
2020

2121

22-
2322
module.exports = function(hydraterFunction, childs) {
24-
25-
2623
/**
2724
* Handle a hydration task:
2825
* - Download the file
@@ -35,7 +32,9 @@ module.exports = function(hydraterFunction, childs) {
3532
*/
3633
return function(job, done) {
3734
var task = job.data;
38-
log.info(task, "Starting task");
35+
var loggingTask = {file_path: task.file_path, callback: task.callback, document: {id: task.document.id, identifier: task.document.identifier}};
36+
37+
log.info(loggingTask, "Starting task");
3938

4039
async.waterfall([
4140
function performHydration(cb) {
@@ -65,10 +64,12 @@ module.exports = function(hydraterFunction, childs) {
6564
cb(err, changes);
6665
}
6766
if(stdout !== "") {
68-
log.info({std: "out"}, stdout);
67+
loggingTask.std = "out";
68+
log.info(loggingTask, stdout);
6969
}
7070
if(stderr !== "") {
71-
log.info({std: "err"}, stderr);
71+
loggingTask.std = "err";
72+
log.info(loggingTask, stderr);
7273
}
7374
clearTimeout(timeout);
7475
};
@@ -138,7 +139,7 @@ module.exports = function(hydraterFunction, childs) {
138139
var changes = {};
139140
changes.hydration_errored = true;
140141
changes.hydration_error = "Task took too long.";
141-
log.warn(task, 'Killing task');
142+
log.warn(loggingTask, 'Killing task');
142143
child.process.kill('SIGTERM');
143144
setTimeout(function() {
144145
if(child.process.connected) {
@@ -177,11 +178,11 @@ module.exports = function(hydraterFunction, childs) {
177178
function patchDocument(changes, cb) {
178179
// Returning null means we won't complete the hydration, and are waiting for something else.
179180
if(changes === null) {
180-
log.info(task, "Skipped task");
181+
log.info(loggingTask, "Skipped task");
181182
return cb();
182183
}
183184

184-
log.info(task, "End of task");
185+
log.info(loggingTask, "End of task");
185186

186187
var apiUrl = url.parse(task.callback, false, true);
187188

@@ -201,7 +202,8 @@ module.exports = function(hydraterFunction, childs) {
201202
}
202203

203204
if(res && res.statusCode && res.statusCode !== 204) {
204-
log.warn({code: res.statusCode}, "Server refused data!");
205+
loggingTask.code = res.statusCode;
206+
log.warn(loggingTask, "Server refused data!");
205207
}
206208

207209
cb(null);

0 commit comments

Comments
 (0)