UNPKG

@atomiqlabs/base

Version:

Base classes and interfaces for atomiq protocol

25 lines (24 loc) 969 B
/** * Type of the logger * * @internal */ export type LoggerType = { debug: (msg: string, ...args: any[]) => void, info: (msg: string, ...args: any[]) => void, warn: (msg: string, ...args: any[]) => void, error: (msg: string, ...args: any[]) => void }; /** * Getter function to create a logger instance * * @internal */ export function getLogger(prefix: string): LoggerType { return { debug: (msg, ...args) => (global as any).atomiqLogLevel >= 3 && console.debug(prefix + msg, ...args), info: (msg, ...args) => (global as any).atomiqLogLevel >= 2 && console.info(prefix + msg, ...args), warn: (msg, ...args) => ((global as any).atomiqLogLevel == null || (global as any).atomiqLogLevel >= 1) && console.warn(prefix + msg, ...args), error: (msg, ...args) => ((global as any).atomiqLogLevel == null || (global as any).atomiqLogLevel >= 0) && console.error(prefix + msg, ...args) }; }