mirror of
https://github.com/eggjs/egg.git
synced 2024-12-04 07:14:30 +00:00
65 lines
1.3 KiB
JavaScript
65 lines
1.3 KiB
JavaScript
const CALL = Symbol('BaseContextLogger#call');
|
|
|
|
class BaseContextLogger {
|
|
/**
|
|
* @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;
|
|
}
|
|
|
|
[CALL](method, args) {
|
|
// add `[${pathName}]` in log
|
|
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[CALL]('debug', args);
|
|
}
|
|
|
|
/**
|
|
* @member {Function} BaseContextLogger#info
|
|
* @param {...any} args - log msg
|
|
* @since 1.2.0
|
|
*/
|
|
info(...args) {
|
|
this[CALL]('info', args);
|
|
}
|
|
|
|
/**
|
|
* @member {Function} BaseContextLogger#warn
|
|
* @param {...any} args - log msg
|
|
* @since 1.2.0
|
|
*/
|
|
warn(...args) {
|
|
this[CALL]('warn', args);
|
|
}
|
|
|
|
/**
|
|
* @member {Function} BaseContextLogger#error
|
|
* @param {...any} args - log msg
|
|
* @since 1.2.0
|
|
*/
|
|
error(...args) {
|
|
this[CALL]('error', args);
|
|
}
|
|
}
|
|
|
|
module.exports = BaseContextLogger;
|