mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-30 06:15:18 +01:00
* refactor(DropdownPopup): set MenuButton `as` prop to `div` to prevent React warning: validateDOMNesting(...): <button> cannot appear as a descendant of <button> * refactor: memoize ChatGroupItem and ControlCombobox components * refactor(OpenAIClient): await stream process finish before finalCompletion event handling * refactor: update useSSE.ts typing to handle null and undefined values in data properties * refactor: set abort scroll to false on SSE connection open * refactor: improve logger functionality with filter support * refactor: update handleScroll typing in MessageContainer component * refactor: update logger.dir call in useChatFunctions to log 'message_stream' tag format instead of the entire submission object as first arg * refactor: fix null check for message object in Message component * refactor: throttle handleScroll to help prevent auto-scrolling issues on new message requests; fix type issues within useMessageProcess * refactor: add abortScrollByIndex logging effect * refactor: update MessageIcon and Icon components to use React.memo for performance optimization * refactor: memoize ConvoIconURL component for performance optimization * chore: type issues * chore: update package version to 0.7.414
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
const isDevelopment = import.meta.env.MODE === 'development';
|
|
const isLoggerEnabled = import.meta.env.VITE_ENABLE_LOGGER === 'true';
|
|
const loggerFilter = import.meta.env.VITE_LOGGER_FILTER || '';
|
|
|
|
type LogFunction = (...args: unknown[]) => void;
|
|
|
|
const createLogFunction = (consoleMethod: LogFunction): LogFunction => {
|
|
return (...args: unknown[]) => {
|
|
if (isDevelopment || isLoggerEnabled) {
|
|
const tag = typeof args[0] === 'string' ? args[0] : '';
|
|
if (shouldLog(tag)) {
|
|
if (tag && args.length > 1) {
|
|
consoleMethod(`[${tag}]`, ...args.slice(1));
|
|
} else {
|
|
consoleMethod(...args);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
const logger = {
|
|
log: createLogFunction(console.log),
|
|
warn: createLogFunction(console.warn),
|
|
error: createLogFunction(console.error),
|
|
info: createLogFunction(console.info),
|
|
debug: createLogFunction(console.debug),
|
|
dir: createLogFunction(console.dir),
|
|
};
|
|
|
|
function shouldLog(tag: string): boolean {
|
|
if (!loggerFilter) {
|
|
return true;
|
|
}
|
|
/* If no tag is provided, always log */
|
|
if (!tag) {
|
|
return true;
|
|
}
|
|
return loggerFilter
|
|
.split(',')
|
|
.some((filter) => tag.toLowerCase().includes(filter.trim().toLowerCase()));
|
|
}
|
|
|
|
export default logger;
|