diff --git a/packages/koishi-core/src/app.ts b/packages/koishi-core/src/app.ts index 24c2e6b837..6a3a190c65 100644 --- a/packages/koishi-core/src/app.ts +++ b/packages/koishi-core/src/app.ts @@ -128,9 +128,8 @@ export class App extends Context { this.receiver.on('before-group', Command.attachGroupFields) this.middleware(this._preprocess) - this.receiver.on('logger', (scope, message) => { - debug('koishi:' + scope)(message) - }) + // apply default logger + this.receiver.on('logger', (scope, message) => debug(scope)(message)) } get users () { @@ -236,7 +235,7 @@ export class App extends Context { } await Promise.all(tasks) this.status = Status.open - this.logger('app').debug('started') + this.logger('koishi:app').debug('started') this.receiver.emit('connect') if (this.selfId && !this._isReady) { this.receiver.emit('ready') @@ -261,7 +260,7 @@ export class App extends Context { this.server.close() } this.status = Status.closed - this.logger('app').debug('stopped') + this.logger('koishi:app').debug('stopped') this.receiver.emit('disconnect') if (appList.every(app => app.status === Status.closed)) { onStopHooks.forEach(hook => hook(...appList)) @@ -270,7 +269,7 @@ export class App extends Context { emitEvent (meta: Meta, event: K, ...payload: Parameters) { if (!meta.$ctxType) { - this.logger('receiver').debug('/', 'emits', event) + this.logger('koishi:receiver').debug('/', 'emits', event) this.receiver.emit(event, ...payload) return } @@ -278,7 +277,7 @@ export class App extends Context { for (const path in this._contexts) { const context = this._contexts[path] if (!context.match(meta)) continue - this.logger('receiver').debug(path, 'emits', event) + this.logger('koishi:receiver').debug(path, 'emits', event) context.receiver.emit(event, ...payload) } } @@ -434,7 +433,7 @@ export class App extends Context { let index = 0 const next = async (fallback?: NextFunction) => { if (!this._middlewareSet.has(counter)) { - return this.logger().warn(new Error(errors.ISOLATED_NEXT)) + return this.logger('koishi').warn(new Error(errors.ISOLATED_NEXT)) } if (fallback) middlewares.push((_, next) => fallback(next)) try { diff --git a/packages/koishi-core/src/command.ts b/packages/koishi-core/src/command.ts index 9aafd0b810..a139ee5009 100644 --- a/packages/koishi-core/src/command.ts +++ b/packages/koishi-core/src/command.ts @@ -284,7 +284,7 @@ export class Command { if (code) return this._sendHint(code, meta) // execute command - this.context.logger('command').debug('execute %s', this.name) + this.context.logger('koishi:command').debug('execute %s', this.name) this.app.emitEvent(meta, 'command', argv) let skipped = false diff --git a/packages/koishi-core/src/context.ts b/packages/koishi-core/src/context.ts index 599b5c6090..024916dc9c 100644 --- a/packages/koishi-core/src/context.ts +++ b/packages/koishi-core/src/context.ts @@ -65,7 +65,7 @@ export class Context { constructor (public readonly identifier: string, private readonly _scope: ContextScope) { this.receiver.on('error', (error) => { - this.logger().warn(error) + this.logger('koishi').warn(error) }) this.logger = (scope = '') => { @@ -145,7 +145,7 @@ export class Context { middleware (middleware: Middleware) { const { maxMiddlewares } = this.app.options if (this.app._middlewares.length >= maxMiddlewares) { - this.logger().warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares))) + this.logger('koishi').warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares))) } else { this.app._middlewares.push([this, middleware]) } @@ -159,7 +159,7 @@ export class Context { prependMiddleware (middleware: Middleware) { const { maxMiddlewares } = this.app.options if (this.app._middlewares.length >= maxMiddlewares) { - this.logger().warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares))) + this.logger('koishi').warn(new Error(format(errors.MAX_MIDDLEWARES, maxMiddlewares))) } else { this.app._middlewares.unshift([this, middleware]) } diff --git a/packages/koishi-core/src/sender.ts b/packages/koishi-core/src/sender.ts index 9269bf9ade..45e642c718 100644 --- a/packages/koishi-core/src/sender.ts +++ b/packages/koishi-core/src/sender.ts @@ -70,9 +70,9 @@ export class Sender { } async get (action: string, params: Record = {}, silent = false): Promise { - this.app.logger('sender').debug('request %s %o', action, params) + this.app.logger('koishi:sender').debug('request %s %o', action, params) const response = await this._get(action, snakeCase(params)) - this.app.logger('sender').debug('response %o', response) + this.app.logger('koishi:sender').debug('response %o', response) const { data, retcode } = response if (retcode === 0 && !silent) { return camelCase(data) diff --git a/packages/koishi-core/src/server.ts b/packages/koishi-core/src/server.ts index 96d504eb58..799664a673 100644 --- a/packages/koishi-core/src/server.ts +++ b/packages/koishi-core/src/server.ts @@ -29,7 +29,7 @@ export abstract class Server { } protected debug (format: any, ...params: any[]) { - this.app?.logger('sender').debug(format, ...params) + this.app?.logger('koishi:sender').debug(format, ...params) } protected prepareMeta (data: any) {