-
Notifications
You must be signed in to change notification settings - Fork 1
/
formatter.js
27 lines (23 loc) · 1010 Bytes
/
formatter.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
/**
* Default formatter
* Formatter must return a function that takes the following arguments:
* - level label, eg: 'debug', 'error', etc
* - scope, the current scope or module name that does the logging
* - formatArgs, an array of arguments: a printf-like format text that can contain placeholder, followed by
* - one or more arguments after the format wil be used as the value of the placeholder
*/
"use strict";
var util = require('util');
module.exports = function(opts_) {
var opts = opts_ || {};
if (opts.omitTimestamp) return formatNoTimestamp;
else return format;
};
function format(levelLabel, scope, formatArgs) {
var prefix = '[' + (new Date()).toISOString() + '] [' + levelLabel.toUpperCase() + '] [' + scope + '] - ';
return prefix + util.format.apply(util, formatArgs) + '\n';
}
function formatNoTimestamp(levelLabel, scope, formatArgs) {
var prefix = '[' + levelLabel.toUpperCase() + '] [' + scope + '] - ';
return prefix + util.format.apply(util, formatArgs) + '\n';
}