mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
add log level setting
This commit is contained in:
@@ -2,6 +2,7 @@ import { Fragment } from 'react/jsx-runtime';
|
||||
|
||||
import { AnalyticsSettings } from '/@/renderer/features/settings/components/advanced/analytics-settings';
|
||||
import { ExportImportSettings } from '/@/renderer/features/settings/components/advanced/export-import-settings';
|
||||
import { LoggerSettings } from '/@/renderer/features/settings/components/advanced/logger-settings';
|
||||
import { CacheSettings } from '/@/renderer/features/settings/components/window/cache-settngs';
|
||||
import { UpdateSettings } from '/@/renderer/features/settings/components/window/update-settings';
|
||||
import { Divider } from '/@/shared/components/divider/divider';
|
||||
@@ -11,6 +12,7 @@ const sections = [
|
||||
{ component: UpdateSettings, key: 'update' },
|
||||
{ component: AnalyticsSettings, key: 'analytics' },
|
||||
{ component: ExportImportSettings, key: 'export-import' },
|
||||
{ component: LoggerSettings, key: 'logger' },
|
||||
{ component: CacheSettings, key: 'cache' },
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import {
|
||||
SettingOption,
|
||||
SettingsSection,
|
||||
} from '/@/renderer/features/settings/components/settings-section';
|
||||
import { logFn, LogLevel } from '/@/renderer/utils/logger';
|
||||
import { Select } from '/@/shared/components/select/select';
|
||||
|
||||
const DEFAULT_LOG_LEVEL: LogLevel = process.env.NODE_ENV === 'production' ? 'info' : 'debug';
|
||||
|
||||
export const LoggerSettings = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const getCurrentLogLevel = (): LogLevel => {
|
||||
const stored = localStorage.getItem('log_level');
|
||||
if (stored && ['debug', 'error', 'info', 'warn'].includes(stored)) {
|
||||
return stored as LogLevel;
|
||||
}
|
||||
return DEFAULT_LOG_LEVEL;
|
||||
};
|
||||
|
||||
const handleLogLevelChange = (value: null | string) => {
|
||||
if (!value) return;
|
||||
|
||||
const logLevel = value as LogLevel;
|
||||
localStorage.setItem('log_level', logLevel);
|
||||
|
||||
// Update the logger dynamically
|
||||
if (logFn.updateLogLevel) {
|
||||
logFn.updateLogLevel(logLevel);
|
||||
}
|
||||
};
|
||||
|
||||
const loggerOptions: SettingOption[] = [
|
||||
{
|
||||
control: (
|
||||
<Select
|
||||
data={[
|
||||
{
|
||||
label: t('setting.logLevel', {
|
||||
context: 'optionDebug',
|
||||
postProcess: 'titleCase',
|
||||
}),
|
||||
value: 'debug',
|
||||
},
|
||||
{
|
||||
label: t('setting.logLevel', {
|
||||
context: 'optionInfo',
|
||||
postProcess: 'titleCase',
|
||||
}),
|
||||
value: 'info',
|
||||
},
|
||||
{
|
||||
label: t('setting.logLevel', {
|
||||
context: 'optionWarn',
|
||||
postProcess: 'titleCase',
|
||||
}),
|
||||
value: 'warn',
|
||||
},
|
||||
{
|
||||
label: t('setting.logLevel', {
|
||||
context: 'optionError',
|
||||
postProcess: 'titleCase',
|
||||
}),
|
||||
value: 'error',
|
||||
},
|
||||
]}
|
||||
defaultValue={getCurrentLogLevel()}
|
||||
onChange={handleLogLevelChange}
|
||||
/>
|
||||
),
|
||||
description: t('setting.logLevel', {
|
||||
context: 'description',
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
title: t('setting.logLevel', { postProcess: 'sentenceCase' }),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<SettingsSection
|
||||
options={loggerOptions}
|
||||
title={t('page.setting.logger', { postProcess: 'sentenceCase' })}
|
||||
/>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user