Skip to content

Instantly share code, notes, and snippets.

@lydemann
Last active June 27, 2018 19:11
Show Gist options
  • Save lydemann/7ee5acc8ea74c6e6f544fcaeb453b50c to your computer and use it in GitHub Desktop.
Save lydemann/7ee5acc8ea74c6e6f544fcaeb453b50c to your computer and use it in GitHub Desktop.
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