Skip to content

Commit

Permalink
fix(stark-core): enable correlation-id generation when `loggingFlushD…
Browse files Browse the repository at this point in the history
…isabled == true`

ISSUES CLOSED: #3620
  • Loading branch information
mhenkens committed Jun 4, 2024
1 parent 2d8aead commit 0aeece5
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions packages/stark-core/src/modules/logging/services/logging.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,28 @@ export class StarkLoggingServiceImpl implements StarkLoggingService {
this.consoleWarn = this.getConsole("warn");
this.consoleError = this.getConsole("error");

if (this.appConfig.loggingFlushDisabled) {
return;
}

this.backend = this.appConfig.getBackend("logging");
this.logPersistSize = <number>this.appConfig.loggingFlushPersistSize;
this.logUrl = `${this.backend.url}/${this.appConfig.loggingFlushResourceName}`;
this.generateNewCorrelationId();

this.store.pipe(select(selectStarkLogging)).subscribe((starkLogging: StarkLogging) => {
this.starkLogging = starkLogging;
this.persistLogMessages();
});
if (!this.appConfig.loggingFlushDisabled) {
this.backend = this.appConfig.getBackend("logging");
this.logPersistSize = <number>this.appConfig.loggingFlushPersistSize;
this.logUrl = `${this.backend.url}/${this.appConfig.loggingFlushResourceName}`;

if (window) {
window.addEventListener("beforeunload", (_ev: BeforeUnloadEvent) => {
// Persist the remaining log entries that are still in the store, before leaving the application.
// We need to call the REST service synchronously,
// because the browser has to wait for the REST service to complete.

const data: string = JSON.stringify(Serialize(this.starkLogging, StarkLoggingImpl));
this.sendRequest(this.logUrl, data, false);
this.store.pipe(select(selectStarkLogging)).subscribe((starkLogging: StarkLogging) => {
this.starkLogging = starkLogging;
this.persistLogMessages();
});

if (window) {
window.addEventListener("beforeunload", (_ev: BeforeUnloadEvent) => {
// Persist the remaining log entries that are still in the store, before leaving the application.
// We need to call the REST service synchronously,
// because the browser has to wait for the REST service to complete.

const data: string = JSON.stringify(Serialize(this.starkLogging, StarkLoggingImpl));
this.sendRequest(this.logUrl, data, false);
});
}
}

this.debug(starkLoggingServiceName + " loaded");
Expand Down

0 comments on commit 0aeece5

Please sign in to comment.