-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (28 loc) · 847 Bytes
/
index.js
File metadata and controls
34 lines (28 loc) · 847 Bytes
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
var log = makeLogWithName(undefined);
log.for = makeLogWithName;
function makeLogWithName(name) {
var log = makeLogFunc(name);
log.TODO = makeLogFunc(name, 'TODO');
log.info = makeLogFunc(name, 'INFO');
log.warn = makeLogFunc(name, 'WARN');
log.error = makeLogFunc(name, 'ERROR');
return log;
}
function makeLogFunc(name, type) {
if (name == undefined && type == undefined) {
return function() {
console.error.apply(console, arguments);
};
}
var header = (name == undefined)
? '{' + type + '}'
: (type == undefined)
? '[' + name + ']'
: '[' + name + '] {' + type + '}';
return function() {
var args = arguments.length == 1 ? [arguments[0]] : Array.apply(null, arguments);
args.unshift(header);
console.error.apply(console, args);
};
}
module.exports = log;