@graphql-hive/logger
Version:
78 lines (73 loc) • 2.83 kB
TypeScript
import { L as LogWriter, a as LogLevel, A as Attributes, b as Logger } from './logger-0VFPPle_.js';
export { d as AttributeValue, c as LoggerOptions, M as MaybeLazy, j as jsonStringify } from './logger-0VFPPle_.js';
export { JSONLogWriter } from './writers/json.js';
import '@whatwg-node/disposablestack';
declare const asciMap: {
timestamp: string;
trace: string;
debug: string;
info: string;
warn: string;
error: string;
message: string;
key: string;
reset: string;
};
interface ConsoleLogWriterOptions {
/** @default globalThis.Console */
console?: Pick<Console, 'debug' | 'info' | 'warn' | 'error'>;
/**
* Whether to disable colors in the console output.
*
* @default env.NO_COLOR || false
*/
noColor?: boolean;
/**
* Whether to include the timestamp at the beginning of the log message.
*
* @default false
*/
noTimestamp?: boolean;
/**
* Asynchronously write the logs to the {@link console}. Will not block the main thread,
* but has potential to spam the event loop with log promises. Use with caution.
*
* Note that all of the logs will be written in the order they were called, only not immedietely.
*
* The logs are queued in a macrotask, so they will not block the main thread and will have lower
* priority than microtasks (promises will have priority).
*
* @default false
*/
async?: boolean;
}
declare class ConsoleLogWriter implements LogWriter {
#private;
constructor(opts?: ConsoleLogWriterOptions);
color<T extends string | null | undefined>(style: keyof typeof asciMap, text: T): T;
write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void | Promise<void>;
stringifyAttrs(attrs: Attributes): string;
}
declare class MemoryLogWriter implements LogWriter {
logs: {
level: LogLevel;
msg?: string;
attrs?: unknown;
}[];
write(level: LogLevel, attrs: Attributes | null | undefined, msg: string | null | undefined): void;
}
type LazyLoggerMessage = (() => any | any[]) | any;
/** @deprecated Please migrate to using the {@link Logger} instead.*/
declare class LegacyLogger {
#private;
constructor(logger: Logger);
static from(logger: Logger): LegacyLogger;
log(...args: any[]): void;
warn(...args: any[]): void;
info(...args: any[]): void;
error(...args: any[]): void;
debug(...lazyArgs: LazyLoggerMessage[]): void;
child(name: string | Record<string, string | number>): LegacyLogger;
addPrefix(prefix: string | Record<string, string | number>): LegacyLogger;
}
export { Attributes, ConsoleLogWriter, type ConsoleLogWriterOptions, type LazyLoggerMessage, LegacyLogger, LogLevel, LogWriter, Logger, MemoryLogWriter };