@cumulus/common
Version:
Common utilities used across tasks
112 lines • 3.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertLogLevel = exports.trace = exports.fatal = exports.warn = exports.debug = exports.error = exports.info = exports.logAdditionalKeys = void 0;
const logger_1 = __importDefault(require("@cumulus/logger"));
const isNumber_1 = __importDefault(require("lodash/isNumber"));
const isString_1 = __importDefault(require("lodash/isString"));
function logger() {
return new logger_1.default({
asyncOperationId: process.env.ASYNCOPERATIONID,
executions: process.env.EXECUTIONS,
granules: process.env.GRANULES,
parentArn: process.env.PARENTARN,
sender: process.env.SENDER,
stackName: process.env.STACKNAME,
version: process.env.TASKVERSION,
});
}
/**
* Constructs JSON to log
*
* @param {string} additionalKeys - Any additional key value pairs the user chooses to log
* @param {string} args - Message to log and any other information
* @returns {undefined} - log is printed to stdout, nothing is returned
*/
function logAdditionalKeys(additionalKeys, ...args) {
logger().infoWithAdditionalKeys(additionalKeys, ...args);
}
exports.logAdditionalKeys = logAdditionalKeys;
/**
* Logs the message
*
* @param {string} args - Includes message and any other information to log
*/
function info(...args) {
logger().info(...args);
}
exports.info = info;
/**
* Logs the error
*
* @param {Object} args - Includes error and any other information to log
*/
function error(...args) {
logger().error(...args);
}
exports.error = error;
/**
* Logs the debugger messsages
*
* @param {Object} args - Includes debugger message and any other information to log
*/
function debug(...args) {
logger().debug(...args);
}
exports.debug = debug;
/**
* Logs the Warning messsage
*
* @param {Object} args - Includes Warn message and any other information to log
*/
function warn(...args) {
logger().warn(...args);
}
exports.warn = warn;
/**
* Logs the Fatal messsage
*
* @param {Object} args - Includes Fatal message and any other information to log
*/
function fatal(...args) {
logger().fatal(...args);
}
exports.fatal = fatal;
/**
* Logs the Trace messsage
*
* @param {Object} args - Includes Trace message and any other information to log
*/
function trace(...args) {
logger().trace(...args);
}
exports.trace = trace;
/**
* convert log level from string to number or number to string
*
* @param {string/number} level - log level in string or number
* @returns {number/string} - level in number or string
*/
// @ts-ignore
function convertLogLevel(level) {
warn('@cumulus/common/log.convertLogLevel() is deprecated after version 1.23.2 and will be removed in a future release.');
const mapping = {
fatal: 60,
error: 50,
warn: 40,
info: 30,
debug: 20,
trace: 10,
};
// @ts-ignore
if ((0, isString_1.default)(level))
return mapping[level];
// @ts-ignore
if ((0, isNumber_1.default)(level))
return Object.keys(mapping).find((key) => mapping[key] === level);
return undefined;
}
exports.convertLogLevel = convertLogLevel;
//# sourceMappingURL=log.js.map