chore: data source logger instance (#4181)

This commit is contained in:
ChengLei Shao 2024-04-26 15:53:57 +08:00 committed by GitHub
parent 2dc9622acc
commit 7849bbd889
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import winston, { Logger, format } from 'winston';
import { LoggerOptions, createLogger } from './logger';
import winston, { format, Logger } from 'winston';
import { createLogger, LoggerOptions } from './logger';
import Transport from 'winston-transport';
import { SPLAT } from 'triple-beam';
import { getFormat } from './format';
@ -49,7 +49,7 @@ class SystemLoggerTransport extends Transport {
}
log(info: any, callback: any) {
const { level, message, reqId, app, stack, cause, [SPLAT]: args } = info;
const { level, message, reqId, app, dataSourceKey, stack, cause, [SPLAT]: args } = info;
const logger = level === 'error' && this.errorLogger ? this.errorLogger : this.logger;
const { module, submodule, method, ...meta } = args?.[0] || {};
logger.log({
@ -62,6 +62,7 @@ class SystemLoggerTransport extends Transport {
method: method || '',
app,
reqId,
dataSourceKey: dataSourceKey || 'main',
});
if (cause) {
logger.log({

View File

@ -90,7 +90,8 @@ export class DataSourceModel extends Model {
const dataSource = app.dataSourceManager.factory.create(type, {
...createOptions,
name: this.get('key'),
name: dataSourceKey,
logger: app.logger.child({ dataSourceKey }),
});
if (loadAtAfterStart) {