forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.js
34 lines (30 loc) · 1.04 KB
/
log.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const util = require('util');
module.exports = {
/**
Creates a json (newline delimited) logger.
@param {Object} details fields sent in every log call.
*/
createLogger(details) {
return function(type, values) {
let logObject = { type: type };
Object.assign(logObject, details);
if (typeof values === 'object') {
Object.assign(logObject, values);
} else {
logObject.value = values;
}
process.stdout.write(JSON.stringify(logObject) + '\n');
};
},
fmtLog() {
let args = Array.prototype.slice.call(arguments);
let ts = new Date().toISOString().replace('T', ' ');
return '[taskcluster ' + ts + '] ' + util.format.apply(this, args) + '\n';
},
fmtErrorLog() {
let args = Array.prototype.slice.call(arguments);
// always include a newline before this string, so that it is at the beginning of the line
// where treeherder expects it, even if the last output was not newline-terminated
return '\n[taskcluster:error] ' + util.format.apply(this, args) + '\n';
},
};