mirror of
https://github.com/nocobase/nocobase
synced 2024-11-14 22:36:35 +00:00
chore: datasource sql logger (#5485)
This commit is contained in:
parent
1ee6ca7bef
commit
749b28cef3
@ -22,6 +22,7 @@ export abstract class DataSource extends EventEmitter {
|
||||
public resourceManager: ResourceManager;
|
||||
public acl: ACL;
|
||||
logger: Logger;
|
||||
_sqlLogger: Logger;
|
||||
|
||||
constructor(protected options: DataSourceOptions) {
|
||||
super();
|
||||
@ -32,6 +33,14 @@ export abstract class DataSource extends EventEmitter {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
setSqlLogger(logger: Logger) {
|
||||
this._sqlLogger = logger;
|
||||
}
|
||||
|
||||
get sqlLogger() {
|
||||
return this._sqlLogger || this.logger;
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.options.name;
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
*/
|
||||
public syncManager: SyncManager;
|
||||
public requestLogger: Logger;
|
||||
private sqlLogger: Logger;
|
||||
private _sqlLogger: Logger;
|
||||
protected _logger: SystemLogger;
|
||||
|
||||
constructor(public options: ApplicationOptions) {
|
||||
@ -252,6 +252,10 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
return this._logger;
|
||||
}
|
||||
|
||||
get sqlLogger() {
|
||||
return this._sqlLogger;
|
||||
}
|
||||
|
||||
get log() {
|
||||
return this._logger;
|
||||
}
|
||||
@ -1083,12 +1087,14 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
// Due to the use of custom log levels,
|
||||
// we have to use any type here until Winston updates the type definitions.
|
||||
}) as any;
|
||||
|
||||
this.requestLogger = createLogger({
|
||||
dirname: getLoggerFilePath(this.name),
|
||||
filename: 'request',
|
||||
...(options?.request || {}),
|
||||
});
|
||||
this.sqlLogger = this.createLogger({
|
||||
|
||||
this._sqlLogger = this.createLogger({
|
||||
filename: 'sql',
|
||||
level: 'debug',
|
||||
});
|
||||
@ -1097,7 +1103,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
protected closeLogger() {
|
||||
this.log?.close();
|
||||
this.requestLogger?.close();
|
||||
this.sqlLogger?.close();
|
||||
this._sqlLogger?.close();
|
||||
}
|
||||
|
||||
protected init() {
|
||||
@ -1209,7 +1215,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
|
||||
if (msg.includes('INSERT INTO')) {
|
||||
msg = msg.substring(0, 2000) + '...';
|
||||
}
|
||||
this.sqlLogger.debug({ message: msg, app: this.name, reqId: this.context.reqId });
|
||||
this._sqlLogger.debug({ message: msg, app: this.name, reqId: this.context.reqId });
|
||||
};
|
||||
const dbOptions = options.database instanceof Database ? options.database.options : options.database;
|
||||
const db = new Database({
|
||||
|
@ -96,6 +96,7 @@ export class DataSourceModel extends Model {
|
||||
...createOptions,
|
||||
name: dataSourceKey,
|
||||
logger: app.logger.child({ dataSourceKey }),
|
||||
sqlLogger: app.sqlLogger.child({ dataSourceKey }),
|
||||
});
|
||||
|
||||
if (loadAtAfterStart) {
|
||||
|
Loading…
Reference in New Issue
Block a user