mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 03:46:08 +00:00
feat: database beanchmark (#5615)
* chore: db logging with sql benchmark * chore: log response size
This commit is contained in:
parent
2d41b2acbb
commit
8e1eed7c2f
@ -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
|
||||
|
@ -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 });
|
||||
|
@ -1208,15 +1208,26 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> 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,
|
||||
|
Loading…
Reference in New Issue
Block a user