forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.js
More file actions
43 lines (38 loc) · 948 Bytes
/
logging.js
File metadata and controls
43 lines (38 loc) · 948 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
35
36
37
38
39
40
41
42
43
var kLogsArgument = /^--logs\s*=\s*(.+?)$/;
var kTrimLeft = /^\s+/;
var kTrimRight = /\s+$/;
var kCamelCase = /[-_\s]+(.)?/g;
var logs = findArgvLogs();
function findArgvLogs() {
for (var i = 0; i < process.argv.length; ++i) {
var match = process.argv[i].match(kLogsArgument);
if (match) {
return logsToObject(match[1]);
}
}
return null;
}
function logsToObject(logstr) {
return logstr.
split(',').
reduce(function(obj, key) {
key = camelize(key);
if (key.length > 0) obj[key] = true;
return obj;
}, Object.create(null));
return logs;
}
function camelize(str) {
return str.
replace(kTrimLeft, '').
replace(kTrimRight, '').
replace(kCamelCase, function(match, c) {
return c ? c.toUpperCase() : "";
});
}
function shouldLog(str) {
if (!logs || logs.quiet) return false;
if (logs.all) return true;
return !!logs[camelize(str)];
}
module.exports = shouldLog;