-
-
Save lydemann/7ee5acc8ea74c6e6f544fcaeb453b50c to your computer and use it in GitHub Desktop.
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
import { Injectable } from '@angular/core'; | |
import { LogFields } from '@app/core/log/log-data.interface'; | |
import { Logger } from '@app/core/log/logger'; | |
import { environment } from 'environments/environment'; | |
import { filter } from 'rxjs/operators'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class LogService { | |
private logger: Logger; | |
constructor(private userId: string) {} | |
public initialize() { | |
this.logger = new Logger(environment.appName, environment.endpoints.elasticSearchEndpoint); | |
} | |
public logHttpInfo(info: any, elapsedTime: number, requestPath: string) { | |
// TODO: create and set correlation id | |
const url = location.href; | |
const logFields: LogFields = { | |
environment: environment.env, | |
userId: this.userId, | |
requestPath, | |
elapsedTime, | |
url, | |
}; | |
this.logger.log('Information', `${info}`, logFields); | |
} | |
public logWarning(errorMsg: string) { | |
const url = location.href; | |
const logFields: LogFields = { | |
environment: environment.env, | |
userId: this.userId, | |
requestPath: '', | |
elapsedTime: 0, | |
url: url, | |
}; | |
this.logger.log('Warning', errorMsg, logFields); | |
} | |
public logError(errorMsg: string) { | |
const url = location.href; | |
const logFields: LogFields = { | |
environment: environment.env, | |
userId: this.userId, | |
requestPath: '', | |
elapsedTime: 0, | |
url: url, | |
}; | |
this.logger.log('Error', errorMsg, logFields); | |
} | |
public logInfo(info: any) { | |
const url = location.href; | |
const logFields: LogFields = { | |
environment: environment.env, | |
userId: this.userId, | |
requestPath: '', | |
elapsedTime: 0, | |
url, | |
}; | |
this.logger.log('Information', info, logFields); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment