Skip to content

Commit

Permalink
Introduce logging module
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerstolzenberg committed Mar 16, 2024
1 parent 1c72b84 commit 5aa580d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
7 changes: 2 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { BrowserModule } from '@angular/platform-browser';
import { ToolbarComponent } from './toolbar/toolbar.component';
import { LoggerModule, NgxLoggerLevel } from 'ngx-logger';
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
import { MapComponent } from './map/map.component';
import { MatIcon } from '@angular/material/icon';
import { MatButton } from '@angular/material/button';
import { environment } from '../environments/environment';
import { OptionPaneComponent } from './option-pane/option-pane.component';
import { MatSlideToggle } from '@angular/material/slide-toggle';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
Expand All @@ -18,6 +16,7 @@ import { NotificationsModule } from './notifications/notifications.module';
import { MapModule } from './map/map.module';
import { MatSlider, MatSliderModule, MatSliderThumb } from '@angular/material/slider';
import { FormsModule } from '@angular/forms';
import { LoggingModule } from './logging/logging.module';

@NgModule({
declarations: [HeaderComponent, ToolbarComponent, MapComponent, AppComponent, OptionPaneComponent],
Expand All @@ -31,9 +30,7 @@ import { FormsModule } from '@angular/forms';
MatIcon,
MatButton,
MatSlideToggle,
LoggerModule.forRoot({
level: environment.prodMode ? NgxLoggerLevel.WARN : NgxLoggerLevel.DEBUG
}),
LoggingModule,
I18nModule,
NotificationsModule,
MapModule,
Expand Down
19 changes: 19 additions & 0 deletions src/app/logging/logging.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { NgModule } from '@angular/core';
import { LoggingService } from './logging.service';
import { LoggerModule, NgxLoggerLevel } from 'ngx-logger';
import { environment } from '../../environments/environment';

@NgModule({
exports: [],
imports: [
LoggerModule.forRoot({
level: environment.prodMode ? NgxLoggerLevel.WARN : NgxLoggerLevel.DEBUG
})
],
providers: [
LoggingService
]
})
export class LoggingModule {
// nothing here so far
}
8 changes: 8 additions & 0 deletions src/app/logging/logging.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@angular/core';
import { NGXLogger } from 'ngx-logger';

@Injectable()
export class LoggingService {
constructor(private readonly log: NGXLogger) {
}
}
11 changes: 6 additions & 5 deletions src/app/notifications/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export class NotificationService {
private readonly toastrService: ToastrService,
private readonly i18nService: I18nService,
private readonly log: NGXLogger
) {}
) {
}

showError(message: string, error: HttpErrorResponse | GeolocationPositionError) {
this.log.error(message, error);
Expand All @@ -28,10 +29,10 @@ export class NotificationService {
}

showErrorLocalized(messageKey: string, ...additional: unknown[]) {
this.log.error(messageKey, additional);

firstValueFrom(this.i18nService.translateMultiple(['notifications.error-title', messageKey])).then(values =>
this.toastrService.error(values[1] + ' ' + additional, values[0], options)
firstValueFrom(this.i18nService.translateMultiple(['notifications.error-title', messageKey])).then(values => {
this.log.error(values[1], additional);
this.toastrService.error(values[1] + ' ' + additional, values[0], options);
}
);
}

Expand Down

0 comments on commit 5aa580d

Please sign in to comment.