diff --git a/packages/core/database/src/database.ts b/packages/core/database/src/database.ts index a795b44cee..713e2a32eb 100644 --- a/packages/core/database/src/database.ts +++ b/packages/core/database/src/database.ts @@ -238,7 +238,12 @@ export class Database extends EventEmitter implements AsyncEmitter { }); } + if (options.logging && process.env['DB_SQL_BENCHMARK'] == 'true') { + opts.benchmark = true; + } + this.options = opts; + this.logger.debug( `create database instance: ${safeJsonStringify( // remove sensitive information diff --git a/packages/core/logger/src/request-logger.ts b/packages/core/logger/src/request-logger.ts index 8875f4c53e..a9670f5827 100644 --- a/packages/core/logger/src/request-logger.ts +++ b/packages/core/logger/src/request-logger.ts @@ -66,6 +66,7 @@ export const requestLogger = (appName: string, requestLogger: Logger, options?: cost, app: appName, reqId, + bodySize: ctx.response.length, }; if (Math.floor(status / 100) == 5) { requestLogger.error({ ...info, res: ctx.body?.['errors'] || ctx.body }); diff --git a/packages/core/server/src/application.ts b/packages/core/server/src/application.ts index f29a238332..95348473ff 100644 --- a/packages/core/server/src/application.ts +++ b/packages/core/server/src/application.ts @@ -1208,15 +1208,26 @@ export class Application exten } protected createDatabase(options: ApplicationOptions) { - const logging = (msg: any) => { + const logging = (...args) => { + let msg = args[0]; + if (typeof msg === 'string') { msg = msg.replace(/[\r\n]/gm, '').replace(/\s+/g, ' '); } + if (msg.includes('INSERT INTO')) { msg = msg.substring(0, 2000) + '...'; } - this._sqlLogger.debug({ message: msg, app: this.name, reqId: this.context.reqId }); + + const content: any = { message: msg, app: this.name, reqId: this.context.reqId }; + + if (args[1] && typeof args[1] === 'number') { + content.executeTime = args[1]; + } + + this._sqlLogger.debug(content); }; + const dbOptions = options.database instanceof Database ? options.database.options : options.database; const db = new Database({ ...dbOptions,