diff --git a/backend/src/index.ts b/backend/src/index.ts index a40989fa5d..db810a6f93 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -52,7 +52,7 @@ const LOG_DB_NAME = 'journal.db'; } const loggerService = new LoggerService(encryptionService); - await loggerService.start(oibusSettings.id, oibusSettings.logParameters); + await loggerService.start(oibusSettings.id, oibusSettings.name, oibusSettings.logParameters); const proxyService = new ProxyService(repositoryService.proxyRepository, encryptionService); const healthSignalService = new HealthSignalService( diff --git a/backend/src/service/logger/logger.service.spec.ts b/backend/src/service/logger/logger.service.spec.ts index cdf74c1801..e3254b2b82 100644 --- a/backend/src/service/logger/logger.service.spec.ts +++ b/backend/src/service/logger/logger.service.spec.ts @@ -19,7 +19,8 @@ const encryptionService: EncryptionService = new EncryptionServiceMock('', ''); let service: LoggerService; let logSettings: LogSettings; -const oibusId = 'MyOIBus'; +const oibusId = 'MyOIBusId'; +const oibusName = 'MyOIBusName'; describe('Logger', () => { beforeEach(() => { @@ -77,13 +78,14 @@ describe('Logger', () => { tokenAddress: logSettings.loki.tokenAddress, address: logSettings.loki.address, id: oibusId, + name: oibusName, interval: logSettings.loki.interval }, level: logSettings.loki.level } ]; - await service.start(oibusId, logSettings); + await service.start(oibusId, oibusName, logSettings); expect(pino).toHaveBeenCalledTimes(1); expect(pino).toHaveBeenCalledWith({ @@ -105,7 +107,7 @@ describe('Logger', () => { }); logSettings.database.maxNumberOfLogs = 0; - await service.start(oibusId, logSettings); + await service.start(oibusId, oibusName, logSettings); expect(console.error).toHaveBeenCalledTimes(1); expect(console.error).toHaveBeenCalledWith(new Error('decrypt-error')); @@ -135,13 +137,14 @@ describe('Logger', () => { tokenAddress: logSettings.loki.tokenAddress, address: logSettings.loki.address, id: oibusId, + name: oibusName, interval: logSettings.loki.interval }, level: logSettings.loki.level } ]; - await service.start(oibusId, logSettings); + await service.start(oibusId, oibusName, logSettings); expect(pino).toHaveBeenCalledTimes(1); expect(pino).toHaveBeenCalledWith({ @@ -171,7 +174,7 @@ describe('Logger', () => { } ]; - await service.start(oibusId, logSettings); + await service.start(oibusId, oibusName, logSettings); expect(pino).toHaveBeenCalledTimes(1); expect(pino).toHaveBeenCalledWith({ diff --git a/backend/src/service/logger/logger.service.ts b/backend/src/service/logger/logger.service.ts index d8d46a8563..e2afdebe66 100644 --- a/backend/src/service/logger/logger.service.ts +++ b/backend/src/service/logger/logger.service.ts @@ -30,7 +30,7 @@ class LoggerService { /** * Run the appropriate pino log transports according to the configuration */ - async start(oibusId: string, logParameters: LogSettings): Promise { + async start(oibusId: string, oibusName: string, logParameters: LogSettings): Promise { await createFolder(LOG_FOLDER_NAME); const targets = []; @@ -70,6 +70,7 @@ class LoggerService { address: logParameters.loki.address, tokenAddress: logParameters.loki.tokenAddress, id: oibusId, + name: oibusName, interval: logParameters.loki.interval }, level: logParameters.loki.level diff --git a/backend/src/service/logger/loki-transport.ts b/backend/src/service/logger/loki-transport.ts index d02d2dfa19..c0c2f18c09 100644 --- a/backend/src/service/logger/loki-transport.ts +++ b/backend/src/service/logger/loki-transport.ts @@ -21,6 +21,7 @@ interface LokiOptions { tokenAddress?: string; address: string; id: string; + oibusName: string; interval?: number; batchLimit?: number; } @@ -76,6 +77,7 @@ class LokiTransport { streams.push({ stream: { oibus: this.options.id, + oibusName: this.options.oibusName, level: LEVEL_FORMAT[logLevel], scope: jsonMessage.scope }, diff --git a/backend/src/service/reload.service.spec.ts b/backend/src/service/reload.service.spec.ts index bb738eee38..c10a79f5a4 100644 --- a/backend/src/service/reload.service.spec.ts +++ b/backend/src/service/reload.service.spec.ts @@ -80,11 +80,11 @@ describe('reload service', () => { it('should update log parameters', async () => { const changeLoggerFn = jest.fn(); - const newSettings = { id: 'oibusId', logParameters: {} as LogSettings, healthSignal: {} }; + const newSettings = { id: 'oibusId', name: 'oibusName', logParameters: {} as LogSettings, healthSignal: {} }; service.setWebServerChangeLogger(changeLoggerFn); await service.onUpdateOibusSettings(null, newSettings as EngineSettingsDTO); expect(loggerService.stop).toHaveBeenCalledTimes(1); - expect(loggerService.start).toHaveBeenCalledWith(newSettings.id, newSettings.logParameters); + expect(loggerService.start).toHaveBeenCalledWith(newSettings.id, newSettings.name, newSettings.logParameters); expect(changeLoggerFn).toHaveBeenCalledTimes(1); expect(healthSignalService.setLogger).toHaveBeenCalledTimes(1); expect(healthSignalService.setSettings).toHaveBeenCalledWith(newSettings.healthSignal); diff --git a/backend/src/service/reload.service.ts b/backend/src/service/reload.service.ts index f624ad0b6d..df098ce3ea 100644 --- a/backend/src/service/reload.service.ts +++ b/backend/src/service/reload.service.ts @@ -69,9 +69,13 @@ export default class ReloadService { } async onUpdateOibusSettings(oldSettings: EngineSettingsDTO | null, newSettings: EngineSettingsDTO): Promise { - if (!oldSettings || JSON.stringify(oldSettings.logParameters) !== JSON.stringify(newSettings.logParameters)) { + if ( + !oldSettings || + JSON.stringify(oldSettings.logParameters) !== JSON.stringify(newSettings.logParameters) || + oldSettings.name !== newSettings.name + ) { await this.loggerService.stop(); - await this.loggerService.start(newSettings.id, newSettings.logParameters); + await this.loggerService.start(newSettings.id, newSettings.name, newSettings.logParameters); await this.webServerChangeLoggerCallback(this.loggerService.createChildLogger('web-server')); await this.healthSignalService.setLogger(this.loggerService.createChildLogger('health')); await this.oibusEngine.setLogger(this.loggerService.createChildLogger('engine')); diff --git a/shared/model/logs.model.ts b/shared/model/logs.model.ts index 0245ebabe3..97d54d4cee 100644 --- a/shared/model/logs.model.ts +++ b/shared/model/logs.model.ts @@ -15,6 +15,7 @@ export interface LogStreamValuesCommandDTO { stream: { level: LogLevel; oibus: string; + oibusName: string; scope: string; }; }