UNPKG

@dotcms/analytics

Version:

Official JavaScript library for Content Analytics with DotCMS.

86 lines (85 loc) 2.42 kB
/** * Log level type for the DotLogger */ export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; /** * Log level constants for convenient usage */ export declare const LOG_LEVELS: { readonly DEBUG: "debug"; readonly INFO: "info"; readonly WARN: "warn"; readonly ERROR: "error"; }; /** * Custom logger for DotCMS SDK * Provides structured logging with context identification and configurable log level filtering * * @example * ```typescript * const logger = new DotLogger('Analytics', 'Impression', 'info'); * logger.debug('This will not show'); // Below threshold * logger.info('Tracker initialized'); // Shows * logger.error('Failed to track'); // Shows * ``` */ export declare class DotLogger { private readonly packageName; private readonly context; private readonly minLevel; constructor(packageName: string, context: string, minLevel?: LogLevel); /** * Creates the formatted prefix for log messages * Format: [DotCMS PackageName | Context] [LEVEL] */ private getPrefix; /** * Checks if a log level should be displayed based on the minimum threshold */ private shouldLog; /** * Log a DEBUG level message * Used for detailed debugging information */ debug(...args: unknown[]): void; /** * Log an INFO level message * Used for general informational messages */ info(...args: unknown[]): void; /** * Log a WARN level message * Used for warning messages that don't prevent operation */ warn(...args: unknown[]): void; /** * Log an ERROR level message * Always logs regardless of threshold for critical errors */ error(...args: unknown[]): void; /** * Create a console group for organizing related log messages * Respects the minimum log level threshold */ group(label: string): void; /** * End the current console group * Respects the minimum log level threshold */ groupEnd(): void; /** * Start a timer with the given label * Useful for performance measurements */ time(label: string): void; /** * End a timer and log the elapsed time * Useful for performance measurements */ timeEnd(label: string): void; /** * Log a message (alias for info) * Provided for backward compatibility */ log(...args: unknown[]): void; }