mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 06:06:25 +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.options = opts;
|
||||||
|
|
||||||
this.logger.debug(
|
this.logger.debug(
|
||||||
`create database instance: ${safeJsonStringify(
|
`create database instance: ${safeJsonStringify(
|
||||||
// remove sensitive information
|
// remove sensitive information
|
||||||
|
@ -66,6 +66,7 @@ export const requestLogger = (appName: string, requestLogger: Logger, options?:
|
|||||||
cost,
|
cost,
|
||||||
app: appName,
|
app: appName,
|
||||||
reqId,
|
reqId,
|
||||||
|
bodySize: ctx.response.length,
|
||||||
};
|
};
|
||||||
if (Math.floor(status / 100) == 5) {
|
if (Math.floor(status / 100) == 5) {
|
||||||
requestLogger.error({ ...info, res: ctx.body?.['errors'] || ctx.body });
|
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) {
|
protected createDatabase(options: ApplicationOptions) {
|
||||||
const logging = (msg: any) => {
|
const logging = (...args) => {
|
||||||
|
let msg = args[0];
|
||||||
|
|
||||||
if (typeof msg === 'string') {
|
if (typeof msg === 'string') {
|
||||||
msg = msg.replace(/[\r\n]/gm, '').replace(/\s+/g, ' ');
|
msg = msg.replace(/[\r\n]/gm, '').replace(/\s+/g, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.includes('INSERT INTO')) {
|
if (msg.includes('INSERT INTO')) {
|
||||||
msg = msg.substring(0, 2000) + '...';
|
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 dbOptions = options.database instanceof Database ? options.database.options : options.database;
|
||||||
const db = new Database({
|
const db = new Database({
|
||||||
...dbOptions,
|
...dbOptions,
|
||||||
|
Loading…
Reference in New Issue
Block a user