isoscribe
Version:
An isomorphic logging utility for any JavaScript runtime, providing structured, styled, and extensible logs.
66 lines (65 loc) • 2.29 kB
TypeScript
export type IsoScribeLogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
export type IsoScribeAction = IsoScribeLogLevel | "checkpoint:start" | "checkpoint:end" | "success" | "watch";
type IsoScribeLogFormat = "json" | "string";
declare const LOG_ACTION: Record<IsoScribeAction, string>;
type LogAction = keyof typeof LOG_ACTION;
type IsoScribeOptions = {
/**
* A name that will be converted into camel case that describes
* the logger that is being instantiated. This can be a feature
* or a group of functionality th👀at you want to ensure has it's own
* separate logger
*/
name: string;
/**
* A hex value for the background color of the pill that
* is logged to the console in the browser
* @default #55daf0
*/
pillColor?: string;
/**
* The default log level to be printed
*/
logLevel?: IsoScribeLogLevel;
/**
* The format at which the log should
* be printed
*/
logFormat?: IsoScribeLogFormat;
};
export declare class Isoscribe {
private _logLevel;
private _logFormat;
private _logLevelNameMaxLen;
private _logPill;
private _logName;
constructor(args: IsoScribeOptions);
/** Set log level dynamically */
set logLevel(level: IsoScribeLogLevel);
private shouldLog;
private getLogEnv;
/** Determines text color for contrast */
private getLogPillCss;
/** Assigns a console logger to the log level */
private getLogFn;
/** Gets the formatted name of the logging event */
private getLogLevelName;
/** Get's and formats the timestamp of the logging event */
private getLogTimestamp;
log({ level, message, action, }: {
level: IsoScribeLogLevel;
action?: LogAction;
message: string;
}, ...data: any[]): void;
trace(message: string, ...data: any[]): void;
debug(message: string, ...data: any[]): void;
info(message: string, ...data: any[]): void;
warn(message: string, ...data: any[]): void;
error(message: string, ...data: any[]): void;
fatal(error: Error): void;
success(message: string, ...data: any[]): void;
watch(message: string, ...data: any[]): void;
checkpointStart(message: string): void;
checkpointEnd(): void;
}
export {};