mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add switch for logging
This commit is contained in:
parent
6d6b986a66
commit
dc976cd665
@ -531,7 +531,8 @@
|
|||||||
"resetWebUIDesc1": "Resetting the web UI only resets the browser's local cache of your images and remembered settings. It does not delete any images from disk.",
|
"resetWebUIDesc1": "Resetting the web UI only resets the browser's local cache of your images and remembered settings. It does not delete any images from disk.",
|
||||||
"resetWebUIDesc2": "If images aren't showing up in the gallery or something else isn't working, please try resetting before submitting an issue on GitHub.",
|
"resetWebUIDesc2": "If images aren't showing up in the gallery or something else isn't working, please try resetting before submitting an issue on GitHub.",
|
||||||
"resetComplete": "Web UI has been reset. Refresh the page to reload.",
|
"resetComplete": "Web UI has been reset. Refresh the page to reload.",
|
||||||
"consoleLogLevel": "Console Log Level"
|
"consoleLogLevel": "Log Level",
|
||||||
|
"shouldLogToConsole": "Console Logging"
|
||||||
},
|
},
|
||||||
"toast": {
|
"toast": {
|
||||||
"serverError": "Server Error",
|
"serverError": "Server Error",
|
||||||
|
@ -32,7 +32,6 @@ export const VALID_LOG_LEVELS = [
|
|||||||
'warn',
|
'warn',
|
||||||
'error',
|
'error',
|
||||||
'fatal',
|
'fatal',
|
||||||
'none',
|
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export type InvokeLogLevel = (typeof VALID_LOG_LEVELS)[number];
|
export type InvokeLogLevel = (typeof VALID_LOG_LEVELS)[number];
|
||||||
@ -40,11 +39,12 @@ export type InvokeLogLevel = (typeof VALID_LOG_LEVELS)[number];
|
|||||||
const selector = createSelector(
|
const selector = createSelector(
|
||||||
systemSelector,
|
systemSelector,
|
||||||
(system) => {
|
(system) => {
|
||||||
const { app_version, consoleLogLevel } = system;
|
const { app_version, consoleLogLevel, shouldLogToConsole } = system;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: app_version,
|
version: app_version,
|
||||||
consoleLogLevel,
|
consoleLogLevel,
|
||||||
|
shouldLogToConsole,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -55,14 +55,12 @@ const selector = createSelector(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const useLogger = () => {
|
export const useLogger = () => {
|
||||||
const { version, consoleLogLevel } = useAppSelector(selector);
|
const { version, consoleLogLevel, shouldLogToConsole } =
|
||||||
|
useAppSelector(selector);
|
||||||
|
|
||||||
// The provided Roarr browser log writer uses localStorage to config logging to console
|
// The provided Roarr browser log writer uses localStorage to config logging to console
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (consoleLogLevel === 'none') {
|
if (shouldLogToConsole) {
|
||||||
// Disable console log output
|
|
||||||
localStorage.setItem('ROARR_LOG', 'false');
|
|
||||||
} else {
|
|
||||||
// Enable console log output
|
// Enable console log output
|
||||||
localStorage.setItem('ROARR_LOG', 'true');
|
localStorage.setItem('ROARR_LOG', 'true');
|
||||||
|
|
||||||
@ -71,9 +69,12 @@ export const useLogger = () => {
|
|||||||
'ROARR_FILTER',
|
'ROARR_FILTER',
|
||||||
`context.logLevel:>=${LOG_LEVEL_MAP[consoleLogLevel]}`
|
`context.logLevel:>=${LOG_LEVEL_MAP[consoleLogLevel]}`
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
// Disable console log output
|
||||||
|
localStorage.setItem('ROARR_LOG', 'false');
|
||||||
}
|
}
|
||||||
ROARR.write = createLogWriter();
|
ROARR.write = createLogWriter();
|
||||||
}, [consoleLogLevel]);
|
}, [consoleLogLevel, shouldLogToConsole]);
|
||||||
|
|
||||||
// Update the module-scoped logger context as needed
|
// Update the module-scoped logger context as needed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -30,6 +30,7 @@ import {
|
|||||||
setShouldConfirmOnDelete,
|
setShouldConfirmOnDelete,
|
||||||
setShouldDisplayGuides,
|
setShouldDisplayGuides,
|
||||||
setShouldDisplayInProgressType,
|
setShouldDisplayInProgressType,
|
||||||
|
shouldLogToConsoleChanged,
|
||||||
SystemState,
|
SystemState,
|
||||||
} from 'features/system/store/systemSlice';
|
} from 'features/system/store/systemSlice';
|
||||||
import { uiSelector } from 'features/ui/store/uiSelectors';
|
import { uiSelector } from 'features/ui/store/uiSelectors';
|
||||||
@ -44,6 +45,7 @@ import { ChangeEvent, cloneElement, ReactElement, useCallback } from 'react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { InvokeLogLevel, VALID_LOG_LEVELS } from 'app/logging/useLogger';
|
import { InvokeLogLevel, VALID_LOG_LEVELS } from 'app/logging/useLogger';
|
||||||
import { LogLevelName } from 'roarr';
|
import { LogLevelName } from 'roarr';
|
||||||
|
import { F } from 'ts-toolbelt';
|
||||||
|
|
||||||
const selector = createSelector(
|
const selector = createSelector(
|
||||||
[systemSelector, uiSelector],
|
[systemSelector, uiSelector],
|
||||||
@ -56,6 +58,7 @@ const selector = createSelector(
|
|||||||
saveIntermediatesInterval,
|
saveIntermediatesInterval,
|
||||||
enableImageDebugging,
|
enableImageDebugging,
|
||||||
consoleLogLevel,
|
consoleLogLevel,
|
||||||
|
shouldLogToConsole,
|
||||||
} = system;
|
} = system;
|
||||||
|
|
||||||
const { shouldUseCanvasBetaLayout, shouldUseSliders } = ui;
|
const { shouldUseCanvasBetaLayout, shouldUseSliders } = ui;
|
||||||
@ -70,6 +73,7 @@ const selector = createSelector(
|
|||||||
shouldUseCanvasBetaLayout,
|
shouldUseCanvasBetaLayout,
|
||||||
shouldUseSliders,
|
shouldUseSliders,
|
||||||
consoleLogLevel,
|
consoleLogLevel,
|
||||||
|
shouldLogToConsole,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -122,6 +126,7 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
|
|||||||
shouldUseCanvasBetaLayout,
|
shouldUseCanvasBetaLayout,
|
||||||
shouldUseSliders,
|
shouldUseSliders,
|
||||||
consoleLogLevel,
|
consoleLogLevel,
|
||||||
|
shouldLogToConsole,
|
||||||
} = useAppSelector(selector);
|
} = useAppSelector(selector);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,6 +153,13 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
|
|||||||
[dispatch]
|
[dispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleLogToConsoleChanged = useCallback(
|
||||||
|
(e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
dispatch(shouldLogToConsoleChanged(e.target.checked));
|
||||||
|
},
|
||||||
|
[dispatch]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{cloneElement(children, {
|
{cloneElement(children, {
|
||||||
@ -224,7 +236,13 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
|
|||||||
<Heading size="sm" style={{ fontWeight: 'bold' }}>
|
<Heading size="sm" style={{ fontWeight: 'bold' }}>
|
||||||
Developer
|
Developer
|
||||||
</Heading>
|
</Heading>
|
||||||
|
<IAISwitch
|
||||||
|
label={t('settings.shouldLogToConsole')}
|
||||||
|
isChecked={shouldLogToConsole}
|
||||||
|
onChange={handleLogToConsoleChanged}
|
||||||
|
/>
|
||||||
<IAISelect
|
<IAISelect
|
||||||
|
isDisabled={!shouldLogToConsole}
|
||||||
label={t('settings.consoleLogLevel')}
|
label={t('settings.consoleLogLevel')}
|
||||||
onChange={handleLogLevelChanged}
|
onChange={handleLogLevelChanged}
|
||||||
value={consoleLogLevel}
|
value={consoleLogLevel}
|
||||||
|
@ -101,6 +101,7 @@ export interface SystemState
|
|||||||
* The console output logging level
|
* The console output logging level
|
||||||
*/
|
*/
|
||||||
consoleLogLevel: InvokeLogLevel;
|
consoleLogLevel: InvokeLogLevel;
|
||||||
|
shouldLogToConsole: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialSystemState: SystemState = {
|
const initialSystemState: SystemState = {
|
||||||
@ -149,7 +150,8 @@ const initialSystemState: SystemState = {
|
|||||||
subscribedNodeIds: [],
|
subscribedNodeIds: [],
|
||||||
wereModelsReceived: false,
|
wereModelsReceived: false,
|
||||||
wasSchemaParsed: false,
|
wasSchemaParsed: false,
|
||||||
consoleLogLevel: 'info',
|
consoleLogLevel: 'error',
|
||||||
|
shouldLogToConsole: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const systemSlice = createSlice({
|
export const systemSlice = createSlice({
|
||||||
@ -331,6 +333,9 @@ export const systemSlice = createSlice({
|
|||||||
consoleLogLevelChanged: (state, action: PayloadAction<LogLevelName>) => {
|
consoleLogLevelChanged: (state, action: PayloadAction<LogLevelName>) => {
|
||||||
state.consoleLogLevel = action.payload;
|
state.consoleLogLevel = action.payload;
|
||||||
},
|
},
|
||||||
|
shouldLogToConsoleChanged: (state, action: PayloadAction<boolean>) => {
|
||||||
|
state.shouldLogToConsole = action.payload;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
extraReducers(builder) {
|
extraReducers(builder) {
|
||||||
/**
|
/**
|
||||||
@ -509,6 +514,7 @@ export const {
|
|||||||
cancelTypeChanged,
|
cancelTypeChanged,
|
||||||
subscribedNodeIdsSet,
|
subscribedNodeIdsSet,
|
||||||
consoleLogLevelChanged,
|
consoleLogLevelChanged,
|
||||||
|
shouldLogToConsoleChanged,
|
||||||
} = systemSlice.actions;
|
} = systemSlice.actions;
|
||||||
|
|
||||||
export default systemSlice.reducer;
|
export default systemSlice.reducer;
|
||||||
|
Loading…
Reference in New Issue
Block a user