UNPKG

3.35 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.convertLogLevel = exports.trace = exports.fatal = exports.warn = exports.debug = exports.error = exports.info = exports.logAdditionalKeys = void 0;
7const logger_1 = __importDefault(require("@cumulus/logger"));
8const isNumber_1 = __importDefault(require("lodash/isNumber"));
9const isString_1 = __importDefault(require("lodash/isString"));
10function logger() {
11 return new logger_1.default({
12 asyncOperationId: process.env.ASYNCOPERATIONID,
13 executions: process.env.EXECUTIONS,
14 granules: process.env.GRANULES,
15 parentArn: process.env.PARENTARN,
16 sender: process.env.SENDER,
17 stackName: process.env.STACKNAME,
18 version: process.env.TASKVERSION,
19 });
20}
21/**
22 * Constructs JSON to log
23 *
24 * @param {string} additionalKeys - Any additional key value pairs the user chooses to log
25 * @param {string} args - Message to log and any other information
26 * @returns {undefined} - log is printed to stdout, nothing is returned
27 */
28function logAdditionalKeys(additionalKeys, ...args) {
29 logger().infoWithAdditionalKeys(additionalKeys, ...args);
30}
31exports.logAdditionalKeys = logAdditionalKeys;
32/**
33 * Logs the message
34 *
35 * @param {string} args - Includes message and any other information to log
36 */
37function info(...args) {
38 logger().info(...args);
39}
40exports.info = info;
41/**
42 * Logs the error
43 *
44 * @param {Object} args - Includes error and any other information to log
45 */
46function error(...args) {
47 logger().error(...args);
48}
49exports.error = error;
50/**
51 * Logs the debugger messsages
52 *
53 * @param {Object} args - Includes debugger message and any other information to log
54 */
55function debug(...args) {
56 logger().debug(...args);
57}
58exports.debug = debug;
59/**
60 * Logs the Warning messsage
61 *
62 * @param {Object} args - Includes Warn message and any other information to log
63 */
64function warn(...args) {
65 logger().warn(...args);
66}
67exports.warn = warn;
68/**
69 * Logs the Fatal messsage
70 *
71 * @param {Object} args - Includes Fatal message and any other information to log
72 */
73function fatal(...args) {
74 logger().fatal(...args);
75}
76exports.fatal = fatal;
77/**
78 * Logs the Trace messsage
79 *
80 * @param {Object} args - Includes Trace message and any other information to log
81 */
82function trace(...args) {
83 logger().trace(...args);
84}
85exports.trace = trace;
86/**
87 * convert log level from string to number or number to string
88 *
89 * @param {string/number} level - log level in string or number
90 * @returns {number/string} - level in number or string
91 */
92// @ts-ignore
93function convertLogLevel(level) {
94 warn('@cumulus/common/log.convertLogLevel() is deprecated after version 1.23.2 and will be removed in a future release.');
95 const mapping = {
96 fatal: 60,
97 error: 50,
98 warn: 40,
99 info: 30,
100 debug: 20,
101 trace: 10,
102 };
103 // @ts-ignore
104 if (isString_1.default(level))
105 return mapping[level];
106 // @ts-ignore
107 if (isNumber_1.default(level))
108 return Object.keys(mapping).find((key) => mapping[key] === level);
109 return undefined;
110}
111exports.convertLogLevel = convertLogLevel;
112//# sourceMappingURL=log.js.map
\No newline at end of file