Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
115 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 23 additions & 7 deletions
30
libs/vre/shared/app-error-handler/src/lib/app-error-handler/app-error-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
import { ErrorHandler } from '@angular/core'; | ||
import { ErrorHandler, Injector } from '@angular/core'; | ||
import { AppLoggingService } from '@dasch-swiss/vre/shared/app-logging'; | ||
import { HttpErrorResponse } from '@angular/common/http'; | ||
|
||
export class AppErrorHandler implements ErrorHandler { | ||
constructor(private _injector: Injector) {} | ||
|
||
/** | ||
* Logs out the error to the console. | ||
* The AppLogsService is configured in such a way to catch errors printed | ||
* to the console and forward them to DataDog. | ||
* @param err the error to log. | ||
* Logs out the error using the logging service. | ||
* @param error the error to log. | ||
*/ | ||
handleError(err: any): void { | ||
console.error(err.originalError || err); | ||
handleError(error: Error): void { | ||
const logger = this._injector.get(AppLoggingService); | ||
|
||
if (error instanceof HttpErrorResponse) { | ||
// HTTP related error | ||
logger.error('Caught HttpErrorResponse error', error); | ||
} else if ( | ||
error instanceof TypeError || | ||
error instanceof ReferenceError | ||
) { | ||
// Runtime exceptions mostly induced by Developer's code | ||
logger.error('Caught Type or Reference error', error); | ||
} else { | ||
// catch-all: catch rest of errors | ||
logger.error('Caught error', error); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './lib/app-logging/app-logging.service'; |
8 changes: 4 additions & 4 deletions
8
...src/lib/app-logs/app-logs.service.spec.ts → ...b/app-logging/app-logging.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
libs/vre/shared/app-logging/src/lib/app-logging/app-logging.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Inject, Injectable } from '@angular/core'; | ||
import { datadogLogs, Logger } from '@datadog/browser-logs'; | ||
import { | ||
DspInstrumentationConfig, | ||
DspInstrumentationToken, | ||
} from '@dasch-swiss/vre/shared/app-config'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class AppLoggingService { | ||
private logger: Logger | undefined; | ||
constructor( | ||
@Inject(DspInstrumentationToken) private c: DspInstrumentationConfig | ||
) { | ||
if (c.dataDog.enabled && typeof c.dataDog.clientToken == 'string') { | ||
datadogLogs.init({ | ||
clientToken: c.dataDog.clientToken, | ||
site: c.dataDog.site, | ||
service: c.dataDog.service, | ||
env: c.environment, | ||
forwardErrorsToLogs: true, // forwards console.error logs, uncaught exceptions and network errors to Datadog | ||
forwardConsoleLogs: [], // don't forward any logs (besides console.error - in previous setting) to Datadog | ||
}); | ||
datadogLogs.logger.setHandler(['console', 'http']); | ||
this.logger = datadogLogs.logger; | ||
} | ||
} | ||
|
||
debug(message: string, messageContext?: object, error?: Error) { | ||
if (typeof this.logger != 'undefined') { | ||
datadogLogs.logger.debug(message, messageContext, error); | ||
} else { | ||
console.debug(message, messageContext, error); | ||
} | ||
} | ||
|
||
info(message: string, messageContext?: object, error?: Error) { | ||
if (typeof this.logger != 'undefined') { | ||
this.logger.info(message, messageContext, error); | ||
} else { | ||
console.info(message, messageContext, error); | ||
} | ||
} | ||
warn(message: string, messageContext?: object, error?: Error) { | ||
if (typeof this.logger != 'undefined') { | ||
this.logger.warn(message, messageContext, error); | ||
} else { | ||
console.warn(message, messageContext, error); | ||
} | ||
} | ||
error(message: string, messageContext?: any, error?: Error) { | ||
if (typeof this.logger != 'undefined') { | ||
this.logger.error(message, messageContext, error); | ||
} else { | ||
console.error(message, messageContext, error); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
libs/vre/shared/app-logs/src/lib/app-logs/app-logs.service.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters