@ngworker/lumberjack
Version:
Lumberjack is a versatile Angular logging library, specifically designed to be extended and customized
159 lines (149 loc) • 5.63 kB
TypeScript
import { LumberjackLogDriverConfig, LumberjackLogPayload, LumberjackLogDriver, LumberjackLogDriverLog, LumberjackLog } from '@ngworker/lumberjack';
import { provideHttpClient } from '@angular/common/http';
import * as i0 from '@angular/core';
import { EnvironmentProviders, OnDestroy } from '@angular/core';
/**
* Settings for retrying failed HTTP requests.
*/
interface LumberjackHttpDriverRetryOptions {
/**
* The delay in milliseconds bewteen each retry.
*/
readonly delayMs: number;
/**
* The maximum number of retry attempts made before an HTTP request fails.
*/
readonly maxRetries: number;
}
/**
* Settings used by the HTTP driver.
*/
interface LumberjackHttpDriverInternalConfig extends LumberjackLogDriverConfig {
/**
* The identifier of the application that emitted the log.
*
* This is used by the log store to organize logs.
*/
readonly origin: string;
/**
* Settings for retrying failed HTTP requests.
*/
readonly retryOptions: LumberjackHttpDriverRetryOptions;
/**
* The URL of the log store endpoint.
*
* NOTE! The endpoint matching this url MUST support the POST HTTP verb.
*/
readonly storeUrl: string;
}
/**
* Settings used by the HTTP driver.
*/
type LumberjackHttpDriverConfig = Omit<LumberjackHttpDriverInternalConfig, 'identifier'> & Partial<Pick<LumberjackHttpDriverInternalConfig, 'identifier'>>;
/**
* Settings exclusive to the HTTP driver.
*/
type LumberjackHttpDriverOptions = Omit<LumberjackHttpDriverInternalConfig, keyof LumberjackLogDriverConfig> & Partial<LumberjackLogDriverConfig>;
type LumberjackHttpDriverConfigurationKind = 'options' | 'config';
type LumberjackHttpDriverConfiguration<Kind extends LumberjackHttpDriverConfigurationKind> = {
kind: Kind;
providers: EnvironmentProviders;
};
declare function withHttpConfig(config: LumberjackHttpDriverConfig): LumberjackHttpDriverConfiguration<'config'>;
declare function withHttpOptions(options: LumberjackHttpDriverOptions): LumberjackHttpDriverConfiguration<'options'>;
type HttpClientFeatures = Parameters<typeof provideHttpClient>;
/**
* Returns the [dependency-injection providers](https://angular.io/guide/glossary#provider)
*
* for the `LumberjackHttpDriver` and its `LumberjackHttpDriverConfig`.
* @usageNotes
*
* The function is useful when you want to bootstrap an application using
* the `bootstrapApplication` function and want to make available the `LumberjackHttpDriver` providers.
*
* ```typescript
* bootstrapApplication(RootComponent, {
* providers: [
* provideLumberjack({...}),
* provideLumberjackHttpDriver({...})
* ]
* });
* ```
*
* @publicApi
*/
declare function provideLumberjackHttpDriver<Kind extends LumberjackHttpDriverConfigurationKind>(configuration: LumberjackHttpDriverConfiguration<Kind>, ...features: HttpClientFeatures): EnvironmentProviders[];
declare class LumberjackHttpDriverError extends Error {
constructor(message?: string);
}
/**
* The HTTP driver transports logs to the configured web API log store using the
* POST HTTP verb.
*
* It sends the formatted log and the log including the optional log payload.
*/
declare class LumberjackHttpDriver<TPayload extends LumberjackLogPayload | void = void> implements LumberjackLogDriver<TPayload>, OnDestroy {
#private;
static readonly driverIdentifier = "LumberjackHttpDriver";
readonly config: LumberjackHttpDriverInternalConfig;
ngOnDestroy(): void;
/**
* Send critical log to the log store.
*
* @param param0 The log and its text representation.
*/
logCritical({ formattedLog, log }: LumberjackLogDriverLog<TPayload>): void;
/**
* Send debug log to the log store.
*
* @param param0 The log and its text representation.
*/
logDebug({ formattedLog, log }: LumberjackLogDriverLog<TPayload>): void;
/**
* Send error log to the log store.
*
* @param param0 The log and its text representation.
*/
logError({ formattedLog, log }: LumberjackLogDriverLog<TPayload>): void;
/**
* Send info log to the log store.
*
* @param param0 The log and its text representation.
*/
logInfo({ formattedLog, log }: LumberjackLogDriverLog<TPayload>): void;
/**
* Send trace log to the log store.
*
* @param param0 The log and its text representation.
*/
logTrace({ formattedLog, log }: LumberjackLogDriverLog<TPayload>): void;
/**
* Send warning log to the log store.
*
* @param param0 The log and its text representation.
*/
logWarning({ formattedLog, log }: LumberjackLogDriverLog<TPayload>): void;
static ɵfac: i0.ɵɵFactoryDeclaration<LumberjackHttpDriver<any>, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<LumberjackHttpDriver<any>>;
}
/**
* The HTTP request sent to the configured log store.
*/
interface LumberjackHttpLog<TPayload extends LumberjackLogPayload | void = void> {
/**
* The text representation of the log.
*/
readonly formattedLog: string;
/**
* The log. Optionally supports a log payload.
*/
readonly log: LumberjackLog<TPayload>;
/**
* The identifier of the application that emitted the log.
*
* This is used by the log store to organize logs.
*/
readonly origin: string;
}
export { LumberjackHttpDriver, LumberjackHttpDriverError, provideLumberjackHttpDriver, withHttpConfig, withHttpOptions };
export type { LumberjackHttpDriverConfig, LumberjackHttpDriverOptions, LumberjackHttpDriverRetryOptions, LumberjackHttpLog };