logpipes
Version:
Console.log transformation pipes
43 lines (42 loc) • 2 kB
TypeScript
export declare const LOG_LEVELS: readonly ["debug", "error", "info", "log", "trace", "warn"];
export type LogLevel = typeof LOG_LEVELS[number];
export type LogPipeResult = unknown[] | {
level: LogLevel;
args: unknown[];
};
export interface LogPipe<ResultType extends LogPipeResult = LogPipeResult> {
/**
* LogPipe is a functional interface that accepts a LogLevel and
* a list of arguments and transforms it into another list of arguments.
* The return is an array of transformed arguments.
* If the log pipe needs to change the log level, it should return an object with an updated `level` field.
*/
(level: LogLevel, ...args: unknown[]): ResultType;
onInstall?: () => void;
onUninstall?: () => void;
}
type ConsoleLogFn = (...args: unknown[]) => void;
/**
* Adds the pipe to the list of active console overrides.
* The pipes are called in the order they are installed.
*/
export declare function installConsoleOverride(pipe: LogPipe | Array<LogPipe>): void;
/**
* Adds the pipes to the list of active console overrides.
* The pipes are called in the order they are installed.
*/
export declare function installConsoleOverrides(...pipes: Array<LogPipe>): void;
/** Removes the given pipe from the active console overrides. */
export declare function uninstallConsoleOverride(pipe: LogPipe | Array<LogPipe>): void;
/** Removes the given pipes from the active console overrides. */
export declare function uninstallConsoleOverrides(...pipes: Array<LogPipe>): void;
/** Uninstall all existing console overrides. */
export declare function uninstallAllConsoleOverrides(): void;
/** Returns a list of all console overrides. */
export declare function getConsoleOverrides(): Array<LogPipe>;
/**
* Returns set of console.[log] methods captured during installation of the first pipe.
* If no pipe is installed, returns current console[log] methods.
*/
export declare function getOriginalConsoleMethods(): Record<LogLevel, ConsoleLogFn>;
export {};