openapi-modifier
Version:
This package allows you to automate the process of modifying OpenAPI specifications by applying a set of predefined rules
122 lines (121 loc) • 4.13 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsoleLogger = void 0;
const chalk_1 = __importDefault(require("chalk"));
const debug_1 = __importDefault(require("debug"));
class ConsoleLogger {
constructor({ minLevel, name }) {
this.minLevel = ConsoleLogger.typeLevelMap.info;
this.checkIsAllowed = (level) => {
return ConsoleLogger.typeLevelMap[level] >= this.minLevel;
};
this.debugTrace = (message) => {
if (this.debug.enabled) {
this.debug(message);
}
};
this.clone = (name) => {
return new ConsoleLogger({
minLevel: this.minLevel,
name,
});
};
this.trace = (message, obj) => {
this.debugTrace(message);
if (!this.checkIsAllowed('trace')) {
return;
}
console.log(`${this.logsPrefix}${message}${obj ? JSON.stringify(obj, null, 4) : ''}`);
};
this.info = (message) => {
this.debugTrace(message);
if (!this.checkIsAllowed('info')) {
return;
}
console.info(this.logsPrefix + message);
};
this.notImportantWarning = (message) => {
this.debugTrace(message);
if (!this.checkIsAllowed('not-important-warning')) {
return;
}
console.log(chalk_1.default.grey(this.logsPrefix + message));
};
this.error = (error, message) => {
this.debugTrace('Error');
if (message) {
this.debugTrace(message);
}
if (!this.checkIsAllowed('error')) {
return;
}
if (message) {
console.log(chalk_1.default.bold.red(this.logsPrefix + message));
this.debugTrace(message);
}
console.log(chalk_1.default.bold.red('Error details:'));
console.error(error);
};
this.errorMessage = (message) => {
this.debugTrace('Error message');
if (message) {
this.debugTrace(message);
}
if (!this.checkIsAllowed('error')) {
return;
}
if (message) {
console.log(chalk_1.default.bold.red(this.logsPrefix + message));
this.debugTrace(message);
}
console.log(chalk_1.default.bold.red('Error details:'));
console.error(message);
};
this.warning = (message) => {
this.debugTrace(message);
if (!this.checkIsAllowed('warning')) {
return;
}
console.log(chalk_1.default.bold.yellow(this.logsPrefix + message));
};
this.success = (message) => {
this.debugTrace(message);
if (!this.checkIsAllowed('success')) {
return;
}
console.log(chalk_1.default.bold.green(this.logsPrefix + message));
};
this.helpInfo = (message) => {
if (!message) {
return;
}
this.debugTrace(message);
console.log(chalk_1.default.bold.grey(message));
};
this.getHelpInfo = () => {
if (this.debug.enabled) {
// TODO message
return `For see more logs env DEBUG=df*`;
}
return ``;
};
if (minLevel !== undefined) {
this.minLevel = minLevel;
}
this.debug = (0, debug_1.default)(`${ConsoleLogger.debugPrefix}:${name}`);
this.logsPrefix = name ? `${name}: ` : '';
}
}
exports.ConsoleLogger = ConsoleLogger;
ConsoleLogger.typeLevelMap = {
trace: 0,
info: 1,
'not-important-warning': 2,
warning: 3,
error: 4,
success: 5,
};
ConsoleLogger.debugPrefix = 'openapi-modifier';