UNPKG

moh-common-lib

Version:

A library of Angular components, services, and styles for B.C. Government Ministry of Health (MoH).

81 lines (80 loc) 3.09 kB
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { AbstractHttpService } from './abstract-api-service'; export declare enum CommonLogEvents { navigation = "navigation", error = "error", submission = "submission" } export interface CommonLogMessage { /** The type of event being logged. */ event: string; [key: string]: any; } export declare class CommonLogger extends AbstractHttpService { protected http: HttpClient; /** * The HTTP Headers which go with each request. These MUST be set if you are * using the logger. Fields include: * * - program (REQUIRED, the application wide code) * - applicationId (REQUIRED, like sessionId) * - request_method (REQUIRED, 'POST') * - logsource: (REQUIRED, window.location.hostname) * - http_x_forwarded_host (REQUIRED, window.location.hostname) * */ protected _headers: HttpHeaders; private url; constructor(http: HttpClient); applicationId: string; programName: string; setURL(newURL: string): void; log(message: any): void; logError(errorMessage: any): void; /** * Log a message to Splunk. This is the main way to send logs and * automatically includes meta-data. You do **not** need to subscribe to the * response, as the service already does that. The input object must have an * 'event' property set, everything else is optional. * * Example: * ``` this.logService.log({ event: 'submission', dateObj: new Date() }); ``` * @param message A JavaScript object, nesting is fine, with `event` property * set. */ protected _log(message: CommonLogMessage): import("rxjs").Subscription | import("rxjs").Observable<never>; protected _logError(errorMessage: CommonLogMessage): import("rxjs").Subscription | import("rxjs").Observable<never>; /** * Log HTTP errors, e.g. when losing network connectivity or receiving an * error response code. */ logHttpError(error: HttpErrorResponse): import("rxjs").Subscription | import("rxjs").Observable<never>; /** * Internal method to send logs to Splunk, includes meta-data except that's * consistent across all requests, but not specific values like severity * level. * * @param message A JavaScript object or anything that can be toString()'d, * like Date */ private _sendLog; protected handleError(error: HttpErrorResponse): import("rxjs").Observable<never>; /** * Overwrite the inherited httpOptions so we can set responseType to text. * This updates Angular's parsing, and it won't error out due to the server * not responding with JSON. */ protected readonly httpOptions: any; private setTimestamp; private setSeverity; /** * The headers are easier to search in splunk, and we aren't using tags, so * repurpose it to event type. */ private setTags; }