-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
40 lines (33 loc) · 1.13 KB
/
index.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
35
36
37
38
39
40
'use strict';
var config = require('./src/config');
var loggingFunctions = require('./src/loggingFunctions');
function getLogLevel() {
var level = process.env.LOG_LEVEL;
if (level) {
level = config._logLevels[level.toLowerCase()].level;
}
return level || config._logLevels.trace.level;
}
function meetsLogLevelRequirement(loggerLevel) {
return loggerLevel <= getLogLevel();
}
function createLogFunction(loggingFunctionParams) {
if (loggingFunctionParams.type === config._types.log) {
return function() {
if (meetsLogLevelRequirement(loggingFunctionParams.level)) {
loggingFunctionParams.logFunction(loggingFunctionParams.color, arguments);
}
};
} else if (loggingFunctionParams.type === config._types.line) {
return function(char, length) {
if (meetsLogLevelRequirement(loggingFunctionParams.level)) {
loggingFunctionParams.logFunction(char, length, m.e, m.w, loggingFunctionParams.color);
}
};
}
}
var m = {};
loggingFunctions.forEach(function(loggingFunctionParams) {
m[loggingFunctionParams.functionName] = createLogFunction(loggingFunctionParams);
});
module.exports = m;