Merge branch 'main' into next

This commit is contained in:
Chareice 2024-10-22 17:23:25 +08:00
commit 53e3f3595c
No known key found for this signature in database
3 changed files with 27 additions and 10 deletions

View File

@ -22,6 +22,7 @@ export abstract class DataSource extends EventEmitter {
public resourceManager: ResourceManager; public resourceManager: ResourceManager;
public acl: ACL; public acl: ACL;
logger: Logger; logger: Logger;
_sqlLogger: Logger;
constructor(protected options: DataSourceOptions) { constructor(protected options: DataSourceOptions) {
super(); super();
@ -32,6 +33,14 @@ export abstract class DataSource extends EventEmitter {
this.logger = logger; this.logger = logger;
} }
setSqlLogger(logger: Logger) {
this._sqlLogger = logger;
}
get sqlLogger() {
return this._sqlLogger || this.logger;
}
get name() { get name() {
return this.options.name; return this.options.name;
} }

View File

@ -225,7 +225,6 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
private _maintainingCommandStatus: MaintainingCommandStatus; private _maintainingCommandStatus: MaintainingCommandStatus;
private _maintainingStatusBeforeCommand: MaintainingCommandStatus | null; private _maintainingStatusBeforeCommand: MaintainingCommandStatus | null;
private _actionCommand: Command; private _actionCommand: Command;
private sqlLogger: Logger;
constructor(public options: ApplicationOptions) { constructor(public options: ApplicationOptions) {
super(); super();
@ -238,6 +237,18 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
} }
} }
private _sqlLogger: Logger;
get sqlLogger() {
return this._sqlLogger;
}
protected _logger: SystemLogger;
get logger() {
return this._logger;
}
protected _started: Date | null = null; protected _started: Date | null = null;
/** /**
@ -247,12 +258,6 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
return this._started; return this._started;
} }
protected _logger: SystemLogger;
get logger() {
return this._logger;
}
get log() { get log() {
return this._logger; return this._logger;
} }
@ -1084,12 +1089,14 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
// Due to the use of custom log levels, // Due to the use of custom log levels,
// we have to use any type here until Winston updates the type definitions. // we have to use any type here until Winston updates the type definitions.
}) as any; }) as any;
this.requestLogger = createLogger({ this.requestLogger = createLogger({
dirname: getLoggerFilePath(this.name), dirname: getLoggerFilePath(this.name),
filename: 'request', filename: 'request',
...(options?.request || {}), ...(options?.request || {}),
}); });
this.sqlLogger = this.createLogger({
this._sqlLogger = this.createLogger({
filename: 'sql', filename: 'sql',
level: 'debug', level: 'debug',
}); });
@ -1098,7 +1105,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
protected closeLogger() { protected closeLogger() {
this.log?.close(); this.log?.close();
this.requestLogger?.close(); this.requestLogger?.close();
this.sqlLogger?.close(); this._sqlLogger?.close();
} }
protected init() { protected init() {
@ -1210,7 +1217,7 @@ export class Application<StateT = DefaultState, ContextT = DefaultContext> exten
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 }); this._sqlLogger.debug({ message: msg, app: this.name, reqId: this.context.reqId });
}; };
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({

View File

@ -96,6 +96,7 @@ export class DataSourceModel extends Model {
...createOptions, ...createOptions,
name: dataSourceKey, name: dataSourceKey,
logger: app.logger.child({ dataSourceKey }), logger: app.logger.child({ dataSourceKey }),
sqlLogger: app.sqlLogger.child({ dataSourceKey }),
}); });
if (loadAtAfterStart) { if (loadAtAfterStart) {