@xraph/smartform-react
Version:
React library for rendering and validating SmartForms with shadcn components
125 lines (124 loc) • 3.58 kB
TypeScript
/**
* React Logger
*
* A utility for logging in React applications that can be
* automatically disabled in production environments.
*/
export type LogLevel = "debug" | "info" | "warn" | "error";
export type LoggerConfig = {
enabled: boolean;
level: LogLevel;
prefix?: string;
showTimestamp?: boolean;
extendedInfo?: boolean;
};
export declare const LOG_LEVELS: Record<LogLevel, number>;
/**
* React Logger class for consistent, configurable logging
*/
declare class ReactLogger {
config: LoggerConfig;
componentName?: string;
/**
* Create a new logger instance
*
* @param config Logger configuration or boolean to enable/disable
* @param componentName Optional component name for context
*/
constructor(config?: LoggerConfig | boolean, componentName?: string);
/**
* Create a new logger instance for a specific component
*
* @param componentName Component name
* @returns A new logger instance with the same config
*/
forComponent(componentName: string): ReactLogger;
/**
* Format a message with optional prefix, timestamp, and component name
*
* @param message The message to format
* @returns Formatted message
*/
formatMessage(message: string): string;
/**
* Check if a log level should be displayed
*
* @param level The log level to check
* @returns Whether the log should be displayed
*/
shouldLog(level: LogLevel): boolean;
/**
* Log a debug message
*
* @param message Message or object to log
* @param args Additional arguments to log
*/
debug(message: any, ...args: any[]): void;
/**
* Log a debug message
*
* @param message Message or object to log
* @param args Additional arguments to log
*/
log(message: any, ...args: any[]): void;
/**
* Log an info message
*
* @param message Message or object to log
* @param args Additional arguments to log
*/
info(message: any, ...args: any[]): void;
/**
* Log a warning message
*
* @param message Message or object to log
* @param args Additional arguments to log
*/
warn(message: any, ...args: any[]): void;
/**
* Log an error message
*
* @param message Message or object to log
* @param args Additional arguments to log
*/
error(message: any, ...args: any[]): void;
/**
* Log a message with a group
*
* @param groupName Name of the group
* @param callback Function to execute within the group
*/
group(groupName: string, callback: () => void): void;
/**
* Log a collapsible group
*
* @param groupName Name of the group
* @param callback Function to execute within the group
*/
groupCollapsed(groupName: string, callback: () => void): void;
/**
* Log an object as a table
*
* @param data Data to display as a table
* @param columns Optional column names to include
*/
table(data: any, columns?: string[]): void;
/**
* Start a timer for performance measurement
*
* @param label Timer label
*/
time(label: string): void;
/**
* End a timer and log the duration
*
* @param label Timer label
*/
timeEnd(label: string): void;
}
export declare class ReactLoggerWithContext extends ReactLogger {
constructor(config?: LoggerConfig | boolean);
withContext(): ReactLogger;
}
declare const Logger: ReactLoggerWithContext;
export default Logger;