Skip to content

Commit

Permalink
Debug Log toggle added
Browse files Browse the repository at this point in the history
  • Loading branch information
salty2011 committed Jan 15, 2025
1 parent eef5326 commit 1350849
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/config/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class ConfigManager {
usersPath: '/config/users',
cachePath: '/config/cache/artwork',
steamGridDbApiKey: '',
debugEnabled: false,
users: {},
currentUser: undefined
};
Expand Down
24 changes: 23 additions & 1 deletion src/components/AdminSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
Snackbar,
Alert,
InputAdornment,
IconButton
IconButton,
FormControlLabel,
Switch
} from '@mui/material';
import { Visibility, VisibilityOff } from '@mui/icons-material';
import { AdminConfig } from '../types/config';
Expand Down Expand Up @@ -105,6 +107,26 @@ export const AdminSettings: React.FC<AdminSettingsProps> = ({ config, onSave })
),
}}
/>

<FormControlLabel
control={
<Switch
checked={settings.debugEnabled}
onChange={(e) => {
setSettings({ ...settings, debugEnabled: e.target.checked });
Logger.debug('Debug mode toggled', 'AdminSettings', { enabled: e.target.checked });
}}
/>
}
label={
<Box>
<Typography>Debug Mode</Typography>
<Typography variant="caption" color="text.secondary">
Enable detailed logging for troubleshooting
</Typography>
</Box>
}
/>

<Box sx={{ display: 'flex', gap: 2, mt: 2 }}>
<Button
Expand Down
1 change: 1 addition & 0 deletions src/services/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const ConfigService = {
usersPath: '/config/users',
cachePath: '/config/cache/artwork',
steamGridDbApiKey: '',
debugEnabled: false,
users: {},
currentUser: undefined
};
Expand Down
10 changes: 7 additions & 3 deletions src/services/LogService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ConfigService } from './ConfigService';

export type LogLevel = 'debug' | 'info' | 'warn' | 'error';

export interface LogEntry {
Expand Down Expand Up @@ -98,10 +100,12 @@ class Logger {
};
}

static debug(message: string, component?: string, data?: any) {
if (this.shouldLog('debug')) {
this.writeLog(this.formatLogEntry('debug', message, component, data));
static debug(message: string, component?: string, data?: unknown): void {
// Only log debug messages if debug mode is enabled
if (!ConfigService.isInitialized || !ConfigService.getConfig().debugEnabled) {
return;
}
this.writeLog(this.formatLogEntry('debug', message, component, data));
}

static info(message: string, component?: string, data?: any) {
Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AdminConfig {
usersPath: string;
cachePath: string;
steamGridDbApiKey: string;
debugEnabled: boolean;
users: Record<string, UserConfig>;
}

Expand Down

0 comments on commit 1350849

Please sign in to comment.