egg
Version:
A web application framework for Node.js
58 lines (57 loc) • 1.19 kB
JavaScript
//#region src/lib/core/base_context_logger.ts
var BaseContextLogger = class {
#ctx;
#pathName;
/**
* @class
* @param {Context} ctx - context instance
* @param {String} pathName - class path name
* @since 1.0.0
*/
constructor(ctx, pathName) {
/**
* @member {Context} BaseContextLogger#ctx
* @since 1.2.0
*/
this.#ctx = ctx;
this.#pathName = pathName;
}
_log(method, args) {
if (this.#pathName && typeof args[0] === "string") args[0] = `[${this.#pathName}] ${args[0]}`;
this.#ctx.app.logger[method](...args);
}
/**
* @member {Function} BaseContextLogger#debug
* @param {...any} args - log msg
* @since 1.2.0
*/
debug(...args) {
this._log("debug", args);
}
/**
* @member {Function} BaseContextLogger#info
* @param {...any} args - log msg
* @since 1.2.0
*/
info(...args) {
this._log("info", args);
}
/**
* @member {Function} BaseContextLogger#warn
* @param {...any} args - log msg
* @since 1.2.0
*/
warn(...args) {
this._log("warn", args);
}
/**
* @member {Function} BaseContextLogger#error
* @param {...any} args - log msg
* @since 1.2.0
*/
error(...args) {
this._log("error", args);
}
};
//#endregion
export { BaseContextLogger };