From 017c05bf768daf3f533985a6d3614315b30ff2cb Mon Sep 17 00:00:00 2001 From: Piotr Belke Date: Sat, 7 Dec 2024 12:33:55 +0100 Subject: [PATCH] IKC-378 Frontend logger --- .../consumer-groups/consumer-groups.component.ts | 4 +++- .../apps/kouncil/src/app/rx-stomp.config.ts | 5 ++++- .../kouncil/src/app/schemas/list/schemas.component.ts | 5 ++++- kouncil-frontend/apps/kouncil/src/main.ts | 8 +++++++- .../src/lib/util/http-client.interceptor.ts | 5 ++++- .../libs/feat-send/src/lib/send/send.component.ts | 4 +++- .../src/lib/schema/schema-facade.service.ts | 11 +++++++---- kouncil-frontend/package.json | 2 ++ kouncil-frontend/yarn.lock | 10 ++++++++++ 9 files changed, 44 insertions(+), 10 deletions(-) diff --git a/kouncil-frontend/apps/kouncil/src/app/consumers/consumer-groups/consumer-groups.component.ts b/kouncil-frontend/apps/kouncil/src/app/consumers/consumer-groups/consumer-groups.component.ts index 198653be..83a56d26 100644 --- a/kouncil-frontend/apps/kouncil/src/app/consumers/consumer-groups/consumer-groups.component.ts +++ b/kouncil-frontend/apps/kouncil/src/app/consumers/consumer-groups/consumer-groups.component.ts @@ -18,8 +18,10 @@ import {ServersService} from '@app/common-servers'; import {AbstractTableComponent, TableColumn} from '@app/common-components'; import {MatSort} from '@angular/material/sort'; import {AuthService, SystemFunctionName} from '@app/common-auth'; +import {LoggerFactory} from '@consdata/logger-api'; const CONSUMER_GROUP_FAVOURITE_KEY = 'kouncil-consumer-groups-favourites'; +const log = LoggerFactory.getLogger('ConsumerGroupsComponent'); @Component({ selector: 'app-kafka-consumer-groups', @@ -211,7 +213,7 @@ export class ConsumerGroupsComponent extends AbstractTableComponent implements O duration: 3000 }); }, error => { - console.error(error); + log.error(error); this.snackbar.openFromComponent(SnackBarComponent, { data: new SnackBarData(`Consumer group ${value} couldn't be deleted`, 'snackbar-error', ''), panelClass: ['snackbar'], diff --git a/kouncil-frontend/apps/kouncil/src/app/rx-stomp.config.ts b/kouncil-frontend/apps/kouncil/src/app/rx-stomp.config.ts index 2006e07b..03936996 100644 --- a/kouncil-frontend/apps/kouncil/src/app/rx-stomp.config.ts +++ b/kouncil-frontend/apps/kouncil/src/app/rx-stomp.config.ts @@ -1,5 +1,8 @@ import {environment} from '../environments/environment'; import {RxStompConfig} from '@stomp/rx-stomp'; +import {LoggerFactory} from '@consdata/logger-api'; + +const log = LoggerFactory.getLogger('RxStompConfig'); export const RX_STOMP_CONFIG: RxStompConfig = { brokerURL: `${environment.websocketUrl}`, @@ -7,6 +10,6 @@ export const RX_STOMP_CONFIG: RxStompConfig = { heartbeatOutgoing: 20000, reconnectDelay: 2000, debug: (msg: string): void => { - console.log('RxStompConfig.debug: msg={}', msg); + log.debug('RxStompConfig.debug: msg={}', msg); }, }; diff --git a/kouncil-frontend/apps/kouncil/src/app/schemas/list/schemas.component.ts b/kouncil-frontend/apps/kouncil/src/app/schemas/list/schemas.component.ts index af7514ed..0340a844 100644 --- a/kouncil-frontend/apps/kouncil/src/app/schemas/list/schemas.component.ts +++ b/kouncil-frontend/apps/kouncil/src/app/schemas/list/schemas.component.ts @@ -11,6 +11,9 @@ import {TopicsService} from '@app/feat-topics'; import {Topics} from '@app/common-model'; import {Router} from '@angular/router'; import {AuthService, SystemFunctionName} from '@app/common-auth'; +import {LoggerFactory} from '@consdata/logger-api'; + +const log = LoggerFactory.getLogger('SchemasComponent'); @Component({ selector: 'app-schemas', @@ -214,7 +217,7 @@ export class SchemasComponent extends AbstractTableComponent implements OnInit { duration: 3000 }); }, error => { - console.error(error); + log.error(error); this.snackbar.openFromComponent(SnackBarComponent, { data: new SnackBarData(`Schema version ${version} for subject ${subject} couldn't be deleted`, 'snackbar-error', ''), panelClass: ['snackbar'], diff --git a/kouncil-frontend/apps/kouncil/src/main.ts b/kouncil-frontend/apps/kouncil/src/main.ts index 6fc85974..bc895a9c 100644 --- a/kouncil-frontend/apps/kouncil/src/main.ts +++ b/kouncil-frontend/apps/kouncil/src/main.ts @@ -5,11 +5,17 @@ import {environment} from './environments/environment'; import {AppModule} from './app/app.module'; import {APP_BASE_HREF} from '@angular/common'; import {Backend} from '@app/common-model'; +import {LoggerFactory, LogLevel} from '@consdata/logger-api'; +import {ConsoleLogAppender} from '@consdata/logger-console'; + +LoggerFactory.addAppender(ConsoleLogAppender.instance); +LoggerFactory.setRootLogLevel(LogLevel.INFO); +const log = LoggerFactory.getLogger('Main'); function bootstrap(extraProviders?: StaticProvider[] | undefined) { platformBrowserDynamic(extraProviders) .bootstrapModule(AppModule) - .catch((err) => console.error(err)); + .catch((err) => log.error(err)); } if (environment.production) { diff --git a/kouncil-frontend/libs/common-utils/src/lib/util/http-client.interceptor.ts b/kouncil-frontend/libs/common-utils/src/lib/util/http-client.interceptor.ts index 178642f1..72cb838c 100644 --- a/kouncil-frontend/libs/common-utils/src/lib/util/http-client.interceptor.ts +++ b/kouncil-frontend/libs/common-utils/src/lib/util/http-client.interceptor.ts @@ -13,6 +13,9 @@ import {ProgressBarService} from './progress-bar.service'; import {Router} from '@angular/router'; import {SnackBarComponent} from './snack-bar.component'; import {SnackBarData} from './snack-bar-data'; +import {LoggerFactory} from '@consdata/logger-api'; + +const log = LoggerFactory.getLogger('HttpClientInterceptor'); @Injectable({ providedIn: 'root' @@ -32,7 +35,7 @@ export class HttpClientInterceptor implements HttpInterceptor { this.router.navigate(['/login']); return null; } else { - console.log(JSON.stringify(error)); + log.error(JSON.stringify(error)); const consoleErrorMessage = `Error Code: ${error.status}
Message: ${error.message}\nError message: ${error.error}`; this.snackBar.openFromComponent(SnackBarComponent, { data: new SnackBarData(error.error, 'snackbar-error', 'Close'), diff --git a/kouncil-frontend/libs/feat-send/src/lib/send/send.component.ts b/kouncil-frontend/libs/feat-send/src/lib/send/send.component.ts index a9baf485..5273891e 100644 --- a/kouncil-frontend/libs/feat-send/src/lib/send/send.component.ts +++ b/kouncil-frontend/libs/feat-send/src/lib/send/send.component.ts @@ -16,9 +16,11 @@ import { import {ServersService} from '@app/common-servers'; import {EditorComponent, MonacoEditorService} from '@app/common-components'; import {SnackBarComponent, SnackBarData} from '@app/common-utils'; +import {LoggerFactory} from '@consdata/logger-api'; // eslint-disable-next-line @typescript-eslint/no-explicit-any declare let monaco: any; +const log = LoggerFactory.getLogger('SendComponent'); @Component({ selector: 'app-send', @@ -224,7 +226,7 @@ export class SendComponent implements OnDestroy { duration: 3000 }); }, error => { - console.error(error); + log.error(error); this.snackbar.openFromComponent(SnackBarComponent, { data: new SnackBarData(`Error occurred while sending events to ${messageData.topicName}`, 'snackbar-error', ''), panelClass: ['snackbar'], diff --git a/kouncil-frontend/libs/schema-registry/src/lib/schema/schema-facade.service.ts b/kouncil-frontend/libs/schema-registry/src/lib/schema/schema-facade.service.ts index 3021e827..6b8e38a1 100644 --- a/kouncil-frontend/libs/schema-registry/src/lib/schema/schema-facade.service.ts +++ b/kouncil-frontend/libs/schema-registry/src/lib/schema/schema-facade.service.ts @@ -7,6 +7,9 @@ import {ProtobufUtilsService} from '../protobuf/protobuf-utils.service'; import {JSONSchemaFaker} from 'json-schema-faker'; import {SchemaRegistryService} from './schema-registry.service'; import {AvroUtilsService} from '../avro/avro-utils.service'; +import {LoggerFactory} from '@consdata/logger-api'; + +const log = LoggerFactory.getLogger('SchemaFacadeService'); @Injectable({ providedIn: 'root' @@ -32,18 +35,18 @@ export class SchemaFacadeService { switch (messageFormat) { case MessageFormat.PROTOBUF: example = this.protobufUtilsService.fillProtobufSchemaWithData(plainTextSchema); - console.log(`Found schema, isKey=[${isKey}]`); + log.info(`Found schema, isKey=[${isKey}]`); break; case MessageFormat.JSON: example = JSONSchemaFaker.generate(JSON.parse(plainTextSchema)); - console.log(`Found schema, isKey=[${isKey}]`); + log.info(`Found schema, isKey=[${isKey}]`); break; case MessageFormat.AVRO: example = this.avroUtilsService.fillAvroSchemaWithData(plainTextSchema); - console.log(`Found schema, isKey=[${isKey}]`); + log.info(`Found schema, isKey=[${isKey}]`); break; default: - console.log(`No schema, isKey=[${isKey}]`); + log.info(`No schema, isKey=[${isKey}]`); break; } return example; diff --git a/kouncil-frontend/package.json b/kouncil-frontend/package.json index e92464d6..3fd94027 100644 --- a/kouncil-frontend/package.json +++ b/kouncil-frontend/package.json @@ -24,6 +24,8 @@ "@angular/platform-browser": "15.0.1", "@angular/platform-browser-dynamic": "15.0.1", "@angular/router": "15.0.1", + "@consdata/logger-api": "0.15.0", + "@consdata/logger-console": "0.15.0", "@nrwl/angular": "15.2.1", "@stomp/rx-stomp": "1.1.4", "@swimlane/ngx-datatable": "20.1.0", diff --git a/kouncil-frontend/yarn.lock b/kouncil-frontend/yarn.lock index 125bca43..c101cc2a 100644 --- a/kouncil-frontend/yarn.lock +++ b/kouncil-frontend/yarn.lock @@ -1430,6 +1430,16 @@ resolved "https://registry.yarnpkg.com/@consdata/eslint-config/-/eslint-config-0.21.0.tgz#67610384af577860477f8403e4a939c745e1958f" integrity sha512-Kc0oUL9HjKloDyZSbXuHJmtvKGtg+Y1StrXlplZvWIeBgbH2u6ir8MsXR1Ymn/CL+BX9wM58Ny99j2p+GQP4Yg== +"@consdata/logger-api@0.15.0": + version "0.15.0" + resolved "https://registry.yarnpkg.com/@consdata/logger-api/-/logger-api-0.15.0.tgz#f3c28f484ebe7b199c87a988c1ebfd6fa42282f1" + integrity sha512-CzurbRYuxNViKUawrKDVHAa+EfK/Cyd8W/nWhL9BTT75A0gu+gL+gB8pNc9eVbmUAHxc0QkUrZGbpXYyeSrbKg== + +"@consdata/logger-console@0.15.0": + version "0.15.0" + resolved "https://registry.yarnpkg.com/@consdata/logger-console/-/logger-console-0.15.0.tgz#2b7ea2933e7b31ac28c959f3d3177f742fe1312e" + integrity sha512-UDytdadGhDei8flysjr9sLf/YZDY3MmNDcFPwLpoBNckCT/13nBmSP+RLixNnG1hFOZNQLdAYpfQSbX4YvkjSQ== + "@cspotcode/source-map-support@^0.8.0": version "0.8.1" resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"