mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-10 21:50:14 -07:00
Logger: per-module factory
This commit is contained in:
@@ -7,3 +7,6 @@ export { setupClientUncaughtErrorsLogging } from './interceptors/logger.unhandle
|
||||
|
||||
// re-export the core functionality
|
||||
export { logger } from './logger.client';
|
||||
|
||||
// re-export the module logger factory
|
||||
export { createModuleLogger } from './logger.factory';
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { ClientLogger, LogOptions, LogSource } from './logger.types';
|
||||
import { logger } from './logger.client';
|
||||
|
||||
|
||||
/**
|
||||
* Creates a module-specific logger with a predefined source and optional event prefix.
|
||||
*
|
||||
* @param source The source identifier for all logs from this module
|
||||
* @param eventPrefix Optional prefix to prepend to all log messages
|
||||
* @returns A logger instance with preset source and prefix
|
||||
*/
|
||||
export function createModuleLogger(source: LogSource | string, eventPrefix: string = ''): ClientLogger {
|
||||
// format message with prefix if provided
|
||||
const prefixMessage = eventPrefix
|
||||
? (message: string): string => `${eventPrefix}: ${message}`
|
||||
: (message: string): string => message;
|
||||
|
||||
return {
|
||||
debug: (message: string, details?: any, _overrideSource?: LogSource, options?: LogOptions) =>
|
||||
logger.debug(prefixMessage(message), details, source as LogSource, options),
|
||||
|
||||
info: (message: string, details?: any, _overrideSource?: LogSource, options?: LogOptions) =>
|
||||
logger.info(prefixMessage(message), details, source as LogSource, options),
|
||||
|
||||
warn: (message: string, details?: any, _overrideSource?: LogSource, options?: LogOptions) =>
|
||||
logger.warn(prefixMessage(message), details, source as LogSource, options),
|
||||
|
||||
error: (message: string, details?: any, _overrideSource?: LogSource, options?: LogOptions) =>
|
||||
logger.error(prefixMessage(message), details, source as LogSource, options),
|
||||
|
||||
critical: (message: string, details?: any, _overrideSource?: LogSource, options?: LogOptions) =>
|
||||
logger.critical(prefixMessage(message), details, source as LogSource, options),
|
||||
|
||||
// forward action methods directly to the main logger
|
||||
executeAction: logger.executeAction,
|
||||
markActionCompleted: logger.markActionCompleted,
|
||||
markDismissed: logger.markDismissed,
|
||||
getPendingActions: logger.getPendingActions,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user