forked from aws/aws-lambda-nodejs-runtime-interface-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerboseLog.js
More file actions
49 lines (45 loc) · 1.17 KB
/
Copy pathVerboseLog.js
File metadata and controls
49 lines (45 loc) · 1.17 KB
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
44
45
46
47
48
49
/**
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/
'use strict';
const EnvVarName = 'AWS_LAMBDA_RUNTIME_VERBOSE';
const Tag = 'RUNTIME';
const Verbosity = (() => {
if (!process.env[EnvVarName]) {
return 0;
}
try {
const verbosity = parseInt(process.env[EnvVarName]);
return verbosity < 0 ? 0 : verbosity > 3 ? 3 : verbosity;
} catch (_) {
return 0;
}
})();
exports.logger = function (category) {
return {
verbose: function () {
if (Verbosity >= 1) {
const args = [...arguments].map((arg) =>
typeof arg === 'function' ? arg() : arg,
);
console.log.apply(null, [Tag, category, ...args]);
}
},
vverbose: function () {
if (Verbosity >= 2) {
const args = [...arguments].map((arg) =>
typeof arg === 'function' ? arg() : arg,
);
console.log.apply(null, [Tag, category, ...args]);
}
},
vvverbose: function () {
if (Verbosity >= 3) {
const args = [...arguments].map((arg) =>
typeof arg === 'function' ? arg() : arg,
);
console.log.apply(null, [Tag, category, ...args]);
}
},
};
};