cross-log
Version:
A universal logging package that works in both browser and Node.js environments with environment variable configuration
84 lines • 3.17 kB
TypeScript
/**
* Type-safe wrapper for creating fully typed loggers without casting
* This provides the best TypeScript experience with zero type casting required
*/
import { ILogger, PartialLoggerConfig } from '../core/types';
import { ApiPlugin, DatabasePlugin, AnalyticsPlugin, PerformancePlugin, SecurityPlugin, ApiPluginConfig, DatabasePluginConfig, AnalyticsPluginConfig, PerformancePluginConfig, SecurityPluginConfig } from './types';
/**
* Fully typed logger interface with all possible plugin methods
* No casting required when using this interface
*/
export interface TypedLogger extends ILogger {
api: ApiPlugin;
database: DatabasePlugin;
analytics: AnalyticsPlugin;
performance: PerformancePlugin;
security: SecurityPlugin;
/**
* Enhanced use method with proper return type
*/
use(plugin: any): ILogger;
/**
* Type-safe plugin getter
*/
getPlugin(name: string): any;
}
/**
* Partial typed logger where plugins are optional
*/
export interface PartialTypedLogger extends ILogger {
api?: ApiPlugin;
database?: DatabasePlugin;
analytics?: AnalyticsPlugin;
performance?: PerformancePlugin;
security?: SecurityPlugin;
}
/**
* Plugin method mapping for type safety
*/
interface PluginMethodMap {
api: ApiPlugin;
database: DatabasePlugin;
analytics: AnalyticsPlugin;
performance: PerformancePlugin;
security: SecurityPlugin;
}
/**
* Configuration for creating a typed logger with specific plugins
*/
export interface TypedLoggerConfig {
logger?: PartialLoggerConfig;
plugins?: {
api?: Partial<ApiPluginConfig> | boolean;
database?: Partial<DatabasePluginConfig> | boolean;
analytics?: Partial<AnalyticsPluginConfig> | boolean;
performance?: Partial<PerformancePluginConfig> | boolean;
security?: Partial<SecurityPluginConfig> | boolean;
};
}
/**
* Create a fully typed logger with all plugins loaded
* No type casting required - everything is properly typed
*/
export declare function createTypedLogger(config?: TypedLoggerConfig): TypedLogger;
/**
* Create a partial typed logger with only specified plugins
* Provides type safety while allowing optional plugins
*/
export declare function createPartialTypedLogger(config?: TypedLoggerConfig): PartialTypedLogger;
/**
* Type predicate to check if a plugin is available
*/
export declare function isPluginAvailable<K extends keyof PluginMethodMap>(logger: PartialTypedLogger, plugin: K): logger is PartialTypedLogger & Record<K, PluginMethodMap[K]>;
/**
* Factory function with conditional types for specific plugin combinations
*/
export declare function createLoggerWithSelectedPlugins<T extends Partial<Record<keyof PluginMethodMap, any>>>(loggerConfig?: PartialLoggerConfig, pluginSelection?: T): ILogger & {
[K in keyof T]: K extends keyof PluginMethodMap ? PluginMethodMap[K] : never;
};
/**
* Async factory for lazy-loading plugins
*/
export declare function createAsyncTypedLogger(config?: TypedLoggerConfig, lazyPlugins?: Array<keyof PluginMethodMap>): Promise<PartialTypedLogger>;
export {};
//# sourceMappingURL=typed-wrapper.d.ts.map