chore: add loglevel debug helpers
This commit is contained in:
parent
5398f94f49
commit
2f3db5adc0
3 changed files with 59 additions and 2 deletions
|
@ -31,3 +31,12 @@ export const LOG_LEVEL_PRIORITY = {
|
||||||
[LOG_LEVELS.WARN]: 2,
|
[LOG_LEVELS.WARN]: 2,
|
||||||
[LOG_LEVELS.ERROR]: 3,
|
[LOG_LEVELS.ERROR]: 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Function to update the minimum log level
|
||||||
|
export const setMinLogLevel = (level) => {
|
||||||
|
if (LOG_LEVELS[level] || Object.values(LOG_LEVELS).includes(level)) {
|
||||||
|
config.minLevel = level;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
|
@ -93,4 +93,4 @@ export const logger = new Logger();
|
||||||
export const createLogger = (scopes) => logger.withScopes(scopes);
|
export const createLogger = (scopes) => logger.withScopes(scopes);
|
||||||
|
|
||||||
// Export types and config for external use
|
// Export types and config for external use
|
||||||
export { LOG_LEVELS } from "./config";
|
export { LOG_LEVELS, setMinLogLevel } from "./config";
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
Text,
|
Text,
|
||||||
useTheme,
|
useTheme,
|
||||||
Divider,
|
Divider,
|
||||||
|
RadioButton,
|
||||||
} from "react-native-paper";
|
} from "react-native-paper";
|
||||||
import { createStyles } from "~/theme";
|
import { createStyles } from "~/theme";
|
||||||
import env, { setStaging } from "~/env";
|
import env, { setStaging } from "~/env";
|
||||||
|
@ -18,6 +19,8 @@ import {
|
||||||
toggleEmulatorMode as toggleEmulatorModeService,
|
toggleEmulatorMode as toggleEmulatorModeService,
|
||||||
initEmulatorMode,
|
initEmulatorMode,
|
||||||
} from "~/location/emulatorService";
|
} from "~/location/emulatorService";
|
||||||
|
import { LOG_LEVELS, setMinLogLevel } from "~/lib/logger";
|
||||||
|
import { config as loggerConfig } from "~/lib/logger/config";
|
||||||
|
|
||||||
const reset = async () => {
|
const reset = async () => {
|
||||||
await authActions.logout();
|
await authActions.logout();
|
||||||
|
@ -40,16 +43,26 @@ export default function Developer() {
|
||||||
const [emulatorMode, setEmulatorMode] = useState(false);
|
const [emulatorMode, setEmulatorMode] = useState(false);
|
||||||
const [syncStatus, setSyncStatus] = useState(null); // null, 'syncing', 'success', 'error'
|
const [syncStatus, setSyncStatus] = useState(null); // null, 'syncing', 'success', 'error'
|
||||||
const [syncResult, setSyncResult] = useState("");
|
const [syncResult, setSyncResult] = useState("");
|
||||||
|
const [logLevel, setLogLevel] = useState(LOG_LEVELS.DEBUG);
|
||||||
|
|
||||||
// Initialize emulator mode when component mounts
|
// Initialize emulator mode and log level when component mounts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Initialize the emulator service
|
// Initialize the emulator service
|
||||||
initEmulatorMode();
|
initEmulatorMode();
|
||||||
|
|
||||||
// Set the initial state based on the global service
|
// Set the initial state based on the global service
|
||||||
setEmulatorMode(getEmulatorModeState());
|
setEmulatorMode(getEmulatorModeState());
|
||||||
|
|
||||||
|
// Set the initial log level from config
|
||||||
|
setLogLevel(loggerConfig.minLevel);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Handle log level change
|
||||||
|
const handleLogLevelChange = (level) => {
|
||||||
|
setLogLevel(level);
|
||||||
|
setMinLogLevel(level);
|
||||||
|
};
|
||||||
|
|
||||||
// Handle toggling emulator mode
|
// Handle toggling emulator mode
|
||||||
const handleEmulatorModeToggle = async (enabled) => {
|
const handleEmulatorModeToggle = async (enabled) => {
|
||||||
const newState = await toggleEmulatorModeService(enabled);
|
const newState = await toggleEmulatorModeService(enabled);
|
||||||
|
@ -159,6 +172,33 @@ export default function Developer() {
|
||||||
</View>
|
</View>
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
<Section title="Logging Controls">
|
||||||
|
<Text variant="bodyLarge" style={styles.sectionLabel}>
|
||||||
|
Log Level
|
||||||
|
</Text>
|
||||||
|
<RadioButton.Group
|
||||||
|
onValueChange={handleLogLevelChange}
|
||||||
|
value={logLevel}
|
||||||
|
>
|
||||||
|
<View style={styles.radioRow}>
|
||||||
|
<RadioButton value={LOG_LEVELS.DEBUG} />
|
||||||
|
<Text variant="bodyMedium">DEBUG</Text>
|
||||||
|
</View>
|
||||||
|
<View style={styles.radioRow}>
|
||||||
|
<RadioButton value={LOG_LEVELS.INFO} />
|
||||||
|
<Text variant="bodyMedium">INFO</Text>
|
||||||
|
</View>
|
||||||
|
<View style={styles.radioRow}>
|
||||||
|
<RadioButton value={LOG_LEVELS.WARN} />
|
||||||
|
<Text variant="bodyMedium">WARN</Text>
|
||||||
|
</View>
|
||||||
|
<View style={styles.radioRow}>
|
||||||
|
<RadioButton value={LOG_LEVELS.ERROR} />
|
||||||
|
<Text variant="bodyMedium">ERROR</Text>
|
||||||
|
</View>
|
||||||
|
</RadioButton.Group>
|
||||||
|
</Section>
|
||||||
|
|
||||||
<Section title="Environment URLs">
|
<Section title="Environment URLs">
|
||||||
<View>
|
<View>
|
||||||
<View style={styles.urlRow}>
|
<View style={styles.urlRow}>
|
||||||
|
@ -339,4 +379,12 @@ const useStyles = createStyles(({ wp, hp, scaleText, theme: { colors } }) => ({
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
},
|
},
|
||||||
|
radioRow: {
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
marginVertical: 2,
|
||||||
|
},
|
||||||
|
sectionLabel: {
|
||||||
|
marginBottom: 8,
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Add table
Reference in a new issue