miniprogram-logger
Version:
It is used to log and gather statistics of users' behavior.
116 lines (115 loc) • 4.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var ConsoleManager = /** @class */ (function () {
function ConsoleManager(c) {
this.Telemetry = [];
this.Counters = c ? [c] : [];
this.Loggers = c ? [c] : [];
this.Timers = c ? [c] : [];
}
/**
* 计数
* @param label
* @param value
*/
ConsoleManager.prototype.count = function (label, value) {
if (this.Counters) {
var args_1 = arguments;
this.Counters.forEach(function (v) { return v.count.apply(v, args_1); });
}
};
ConsoleManager.prototype.debug = function () {
if (this.Loggers) {
var args_2 = arguments;
this.Loggers.forEach(function (v) { return v.debug.apply(v, args_2); });
}
};
ConsoleManager.prototype.info = function () {
if (this.Loggers) {
var args_3 = arguments;
this.Loggers.forEach(function (v) { return v.info.apply(v, args_3); });
}
};
ConsoleManager.prototype.warn = function () {
if (this.Loggers) {
var args_4 = arguments;
this.Loggers.forEach(function (v) { return v.warn.apply(v, args_4); });
}
};
ConsoleManager.prototype.error = function () {
if (this.Loggers) {
var args_5 = arguments;
this.Loggers.forEach(function (v) { return v.error.apply(v, args_5); });
}
};
/**
*
* @param level 日志级别
* @param action 日志操作
* @param content 内容
* @param correlationId 关联ID
* @param optionalParams ... 其它参数
*/
ConsoleManager.prototype.log = function (level, action, content, correlationId) {
var optionalParams = [];
for (var _i = 4; _i < arguments.length; _i++) {
optionalParams[_i - 4] = arguments[_i];
}
var args = arguments;
if (level === "time") {
if (this.Timers) {
this.Timers.forEach(function (v) { return v.log.apply(v, Array.prototype.slice.call(args, 1)); });
}
}
else if (level === "telemetry") {
if (this.Telemetry) {
this.Telemetry.forEach(function (v) { return v.record.apply(v, Array.prototype.slice.call(args, 1)); });
}
}
else if (this.Loggers) {
this.Loggers.forEach(function (v) { return v.log.apply(v, args); });
}
};
ConsoleManager.prototype.telemetry = function () {
if (this.Telemetry) {
var args_6 = arguments;
this.Telemetry.forEach(function (v) { return v.record.apply(v, args_6); });
}
};
ConsoleManager.prototype.timeLog = function () {
if (this.Timers) {
var args_7 = arguments;
this.Timers.forEach(function (v) { return v.log.apply(v, args_7); });
}
};
/**
* 开始计时
* @param label - 计时标签
* @param context - 保存上下文信息
*/
ConsoleManager.prototype.time = function (label, context) {
if (this.Timers) {
this.Timers.forEach(function (v) { return v.time(label, context); });
}
};
/**
* 结束计时
* @param label - 计时标签
* @param context - 保存上下文信息
*/
ConsoleManager.prototype.timeEnd = function (label, context) {
if (this.Timers) {
this.Timers.forEach(function (v) { return v.timeEnd(label, context); });
}
};
/**
* 设置统一的上下文信息
*/
ConsoleManager.prototype.setContext = function (key, value) {
this.Loggers.forEach(function (v) { return v.setContext && v.setContext(key, value); });
this.Telemetry.forEach(function (v) { return v.setContext && v.setContext(key, value); });
this.Timers.forEach(function (v) { return v.setContext && v.setContext(key, value); });
};
return ConsoleManager;
}());
exports.ConsoleManager = ConsoleManager;