@kwiz/common
Version:
KWIZ common utilities and helpers for M365 platform
99 lines • 3.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonLogger = exports.CommonConfig = void 0;
exports.config = config;
const _dependencies_1 = require("./_dependencies");
const consolelogger_1 = require("./utils/consolelogger");
/** @deprecated should only be used for 3rd party packages. main project must call config and mark it as sideEffects */
class CommonConfig {
constructor() { }
static get i() {
return _dependencies_1.configInfo;
}
}
exports.CommonConfig = CommonConfig;
var unconfigured = true;
/** @deprecated should only be used for 3rd party packages. main project must call config and mark it as sideEffects */
class CommonLogger {
constructor(name) {
this.instance = null;
this.name = name;
}
get i() {
if (this.instance === null || this.instance.context.prefix !== _dependencies_1.configInfo.ProjectName) {
if (unconfigured)
console.warn('@kwiz/common not configured yet! Call config before this code runs.');
this.instance = consolelogger_1.ConsoleLogger.get(this.name, _dependencies_1.configInfo.ProjectName);
}
return this.instance;
}
;
debug(message) {
return this.i.debug(message);
}
info(message) {
return this.i.info(message);
}
log(message) {
return this.i.log(message);
}
/** output a message when debug is off */
warn(message) {
return this.i.warn(message);
}
/** output a message when debug is off */
error(message) {
return this.i.error(message);
}
/** output a message when debug is off */
trace(message) {
return this.i.trace(message);
}
/**start timer on a label, call timeEnd with the same label to print out the time that passed */
time(label) {
return this.i.time(label);
}
/**start timer on a label, call timeEnd with the same label to print out the time that passed */
timeEnd(label) {
return this.i.timeEnd(label);
}
/**prints an array or dictionary to the console inside a group */
table(data, groupLabel, groupCollapsed) {
return this.i.table(data, groupLabel, groupCollapsed);
}
/**prints a JSON object to the console inside a group */
json(data, groupLabel, groupCollapsed) {
return this.i.json(data, groupLabel, groupCollapsed);
}
/**prints an XML object to the console inside a group. If data is string that looks like an XML - will try to parse it. */
xml(data, groupLabel, groupCollapsed) {
return this.i.xml(data, groupLabel, groupCollapsed);
}
/** render messages inside a group, and closes the group when done. if a label is not provided - a group will not be rendered */
group(renderContent, label, collapsed) {
return this.i.group(renderContent, label, collapsed);
}
groupSync(label, renderContent, options) {
return this.i.groupSync(label, renderContent);
}
async groupAsync(label, renderContent, options) {
return this.i.groupAsync(label, renderContent);
}
}
exports.CommonLogger = CommonLogger;
var unconfigured = true;
;
function config(params) {
(0, _dependencies_1.SetDependencies)(params);
unconfigured = false;
const GetLogger = (name) => {
return consolelogger_1.ConsoleLogger.get(name, _dependencies_1.configInfo.ProjectName);
};
return {
GetLogger: GetLogger,
/** @deprecated call GetLogger instead */
logger: GetLogger,
configInfo: _dependencies_1.configInfo
};
}
//# sourceMappingURL=config.js.map