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.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 types and config for external use
|
||||
export { LOG_LEVELS } from "./config";
|
||||
export { LOG_LEVELS, setMinLogLevel } from "./config";
|
||||
|
|
|
@ -9,6 +9,7 @@ import {
|
|||
Text,
|
||||
useTheme,
|
||||
Divider,
|
||||
RadioButton,
|
||||
} from "react-native-paper";
|
||||
import { createStyles } from "~/theme";
|
||||
import env, { setStaging } from "~/env";
|
||||
|
@ -18,6 +19,8 @@ import {
|
|||
toggleEmulatorMode as toggleEmulatorModeService,
|
||||
initEmulatorMode,
|
||||
} from "~/location/emulatorService";
|
||||
import { LOG_LEVELS, setMinLogLevel } from "~/lib/logger";
|
||||
import { config as loggerConfig } from "~/lib/logger/config";
|
||||
|
||||
const reset = async () => {
|
||||
await authActions.logout();
|
||||
|
@ -40,16 +43,26 @@ export default function Developer() {
|
|||
const [emulatorMode, setEmulatorMode] = useState(false);
|
||||
const [syncStatus, setSyncStatus] = useState(null); // null, 'syncing', 'success', 'error'
|
||||
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(() => {
|
||||
// Initialize the emulator service
|
||||
initEmulatorMode();
|
||||
|
||||
// Set the initial state based on the global service
|
||||
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
|
||||
const handleEmulatorModeToggle = async (enabled) => {
|
||||
const newState = await toggleEmulatorModeService(enabled);
|
||||
|
@ -159,6 +172,33 @@ export default function Developer() {
|
|||
</View>
|
||||
</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">
|
||||
<View>
|
||||
<View style={styles.urlRow}>
|
||||
|
@ -339,4 +379,12 @@ const useStyles = createStyles(({ wp, hp, scaleText, theme: { colors } }) => ({
|
|||
flex: 1,
|
||||
flexWrap: "wrap",
|
||||
},
|
||||
radioRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
marginVertical: 2,
|
||||
},
|
||||
sectionLabel: {
|
||||
marginBottom: 8,
|
||||
},
|
||||
}));
|
||||
|
|
Loading…
Add table
Reference in a new issue