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:
@@ -531,6 +531,7 @@
|
|||||||
"lyrics": "lyrics",
|
"lyrics": "lyrics",
|
||||||
"transcoding": "transcoding",
|
"transcoding": "transcoding",
|
||||||
"discord": "discord",
|
"discord": "discord",
|
||||||
|
"logger": "logger",
|
||||||
"playerFilters": "player filters"
|
"playerFilters": "player filters"
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
@@ -780,6 +781,12 @@
|
|||||||
"lyricFetchProvider": "providers to fetch lyrics from",
|
"lyricFetchProvider": "providers to fetch lyrics from",
|
||||||
"lyricOffset_description": "offset the lyric by the specified amount of milliseconds",
|
"lyricOffset_description": "offset the lyric by the specified amount of milliseconds",
|
||||||
"lyricOffset": "lyric offset (ms)",
|
"lyricOffset": "lyric offset (ms)",
|
||||||
|
"logLevel": "log level",
|
||||||
|
"logLevel_description": "sets the minimum log level to display. debug shows all logs, error only shows errors",
|
||||||
|
"logLevel_optionDebug": "debug",
|
||||||
|
"logLevel_optionError": "error",
|
||||||
|
"logLevel_optionInfo": "info",
|
||||||
|
"logLevel_optionWarn": "warn",
|
||||||
"minimizeToTray_description": "minimize the application to the system tray",
|
"minimizeToTray_description": "minimize the application to the system tray",
|
||||||
"minimizeToTray": "minimize to tray",
|
"minimizeToTray": "minimize to tray",
|
||||||
"minimumScrobblePercentage_description": "the minimum percentage of the song that must be played before it is scrobbled",
|
"minimumScrobblePercentage_description": "the minimum percentage of the song that must be played before it is scrobbled",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Fragment } from 'react/jsx-runtime';
|
|||||||
|
|
||||||
import { AnalyticsSettings } from '/@/renderer/features/settings/components/advanced/analytics-settings';
|
import { AnalyticsSettings } from '/@/renderer/features/settings/components/advanced/analytics-settings';
|
||||||
import { ExportImportSettings } from '/@/renderer/features/settings/components/advanced/export-import-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 { CacheSettings } from '/@/renderer/features/settings/components/window/cache-settngs';
|
||||||
import { UpdateSettings } from '/@/renderer/features/settings/components/window/update-settings';
|
import { UpdateSettings } from '/@/renderer/features/settings/components/window/update-settings';
|
||||||
import { Divider } from '/@/shared/components/divider/divider';
|
import { Divider } from '/@/shared/components/divider/divider';
|
||||||
@@ -11,6 +12,7 @@ const sections = [
|
|||||||
{ component: UpdateSettings, key: 'update' },
|
{ component: UpdateSettings, key: 'update' },
|
||||||
{ component: AnalyticsSettings, key: 'analytics' },
|
{ component: AnalyticsSettings, key: 'analytics' },
|
||||||
{ component: ExportImportSettings, key: 'export-import' },
|
{ component: ExportImportSettings, key: 'export-import' },
|
||||||
|
{ component: LoggerSettings, key: 'logger' },
|
||||||
{ component: CacheSettings, key: 'cache' },
|
{ 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' })}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -27,6 +27,7 @@ interface Logger {
|
|||||||
debug: LogFn;
|
debug: LogFn;
|
||||||
error: LogFn;
|
error: LogFn;
|
||||||
info: LogFn;
|
info: LogFn;
|
||||||
|
updateLogLevel: (level: LogLevel) => void;
|
||||||
warn: LogFn;
|
warn: LogFn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,14 +74,21 @@ setInterval(() => {
|
|||||||
}, DEBOUNCE_INTERVAL);
|
}, DEBOUNCE_INTERVAL);
|
||||||
|
|
||||||
class ConsoleLogger implements Logger {
|
class ConsoleLogger implements Logger {
|
||||||
readonly debug: LogFn;
|
debug: LogFn = NO_OP;
|
||||||
readonly error: LogFn;
|
error: LogFn = NO_OP;
|
||||||
readonly info: LogFn;
|
info: LogFn = NO_OP;
|
||||||
readonly warn: LogFn;
|
updateLogLevel: (level: LogLevel) => void;
|
||||||
|
warn: LogFn = NO_OP;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const level = localStorage.getItem('log_level') || DEFAULT_LOG_LEVEL;
|
const level = (localStorage.getItem('log_level') || DEFAULT_LOG_LEVEL) as LogLevel;
|
||||||
|
this.initializeLoggers(level);
|
||||||
|
this.updateLogLevel = (newLevel: LogLevel) => {
|
||||||
|
this.initializeLoggers(newLevel);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private initializeLoggers(level: LogLevel) {
|
||||||
// Create timestamp wrapper function with colors and debouncing
|
// Create timestamp wrapper function with colors and debouncing
|
||||||
const withTimestamp = (logLevel: string): LogFn => {
|
const withTimestamp = (logLevel: string): LogFn => {
|
||||||
return (message?: any, options?: { category?: string; meta?: any }) => {
|
return (message?: any, options?: { category?: string; meta?: any }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user