mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 08:21:53 +00:00
chore: db logging with sql benchmark
This commit is contained in:
parent
13271128b8
commit
5b31c1006b
@ -234,7 +234,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
|
||||
|
@ -1239,15 +1239,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