refactor(logging): use JSON.stringify for all object logging
Replace collapsed object logging with JSON.stringify to ensure full object details are visible when console logs are copied/pasted. This affects all settings persistence logging: - Loading settings from database - Saving settings to database - API calls to server - Cache updates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -252,10 +252,17 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
|
||||
// Settings are scoped by game name to preserve settings when switching games
|
||||
const mergedInitialState = useMemo(() => {
|
||||
const gameConfig = roomData?.gameConfig as Record<string, any> | null | undefined
|
||||
console.log('[RoomMemoryPairsProvider] Loading settings from database:', {
|
||||
gameConfig,
|
||||
roomId: roomData?.id,
|
||||
})
|
||||
console.log(
|
||||
'[RoomMemoryPairsProvider] Loading settings from database:',
|
||||
JSON.stringify(
|
||||
{
|
||||
gameConfig,
|
||||
roomId: roomData?.id,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
|
||||
if (!gameConfig) {
|
||||
console.log('[RoomMemoryPairsProvider] No gameConfig, using initialState')
|
||||
@@ -264,7 +271,10 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
// Get settings for this specific game (matching)
|
||||
const savedConfig = gameConfig.matching as Record<string, any> | null | undefined
|
||||
console.log('[RoomMemoryPairsProvider] Saved config for matching:', savedConfig)
|
||||
console.log(
|
||||
'[RoomMemoryPairsProvider] Saved config for matching:',
|
||||
JSON.stringify(savedConfig, null, 2)
|
||||
)
|
||||
|
||||
if (!savedConfig) {
|
||||
console.log('[RoomMemoryPairsProvider] No saved config for matching, using initialState')
|
||||
@@ -278,11 +288,18 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
|
||||
difficulty: savedConfig.difficulty ?? initialState.difficulty,
|
||||
turnTimer: savedConfig.turnTimer ?? initialState.turnTimer,
|
||||
}
|
||||
console.log('[RoomMemoryPairsProvider] Merged state:', {
|
||||
gameType: merged.gameType,
|
||||
difficulty: merged.difficulty,
|
||||
turnTimer: merged.turnTimer,
|
||||
})
|
||||
console.log(
|
||||
'[RoomMemoryPairsProvider] Merged state:',
|
||||
JSON.stringify(
|
||||
{
|
||||
gameType: merged.gameType,
|
||||
difficulty: merged.difficulty,
|
||||
turnTimer: merged.turnTimer,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
|
||||
return merged
|
||||
}, [roomData?.gameConfig])
|
||||
@@ -558,10 +575,17 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
|
||||
gameType,
|
||||
},
|
||||
}
|
||||
console.log('[RoomMemoryPairsProvider] Saving gameType to database:', {
|
||||
roomId: roomData.id,
|
||||
updatedConfig,
|
||||
})
|
||||
console.log(
|
||||
'[RoomMemoryPairsProvider] Saving gameType to database:',
|
||||
JSON.stringify(
|
||||
{
|
||||
roomId: roomData.id,
|
||||
updatedConfig,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
updateGameConfig({
|
||||
roomId: roomData.id,
|
||||
gameConfig: updatedConfig,
|
||||
@@ -597,10 +621,17 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
|
||||
difficulty,
|
||||
},
|
||||
}
|
||||
console.log('[RoomMemoryPairsProvider] Saving difficulty to database:', {
|
||||
roomId: roomData.id,
|
||||
updatedConfig,
|
||||
})
|
||||
console.log(
|
||||
'[RoomMemoryPairsProvider] Saving difficulty to database:',
|
||||
JSON.stringify(
|
||||
{
|
||||
roomId: roomData.id,
|
||||
updatedConfig,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
updateGameConfig({
|
||||
roomId: roomData.id,
|
||||
gameConfig: updatedConfig,
|
||||
@@ -636,10 +667,17 @@ export function RoomMemoryPairsProvider({ children }: { children: ReactNode }) {
|
||||
turnTimer,
|
||||
},
|
||||
}
|
||||
console.log('[RoomMemoryPairsProvider] Saving turnTimer to database:', {
|
||||
roomId: roomData.id,
|
||||
updatedConfig,
|
||||
})
|
||||
console.log(
|
||||
'[RoomMemoryPairsProvider] Saving turnTimer to database:',
|
||||
JSON.stringify(
|
||||
{
|
||||
roomId: roomData.id,
|
||||
updatedConfig,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
updateGameConfig({
|
||||
roomId: roomData.id,
|
||||
gameConfig: updatedConfig,
|
||||
|
||||
@@ -672,10 +672,17 @@ async function updateGameConfigApi(params: {
|
||||
roomId: string
|
||||
gameConfig: Record<string, unknown>
|
||||
}): Promise<void> {
|
||||
console.log('[updateGameConfigApi] Sending PATCH to server:', {
|
||||
url: `/api/arcade/rooms/${params.roomId}/settings`,
|
||||
gameConfig: params.gameConfig,
|
||||
})
|
||||
console.log(
|
||||
'[updateGameConfigApi] Sending PATCH to server:',
|
||||
JSON.stringify(
|
||||
{
|
||||
url: `/api/arcade/rooms/${params.roomId}/settings`,
|
||||
gameConfig: params.gameConfig,
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
)
|
||||
|
||||
const response = await fetch(`/api/arcade/rooms/${params.roomId}/settings`, {
|
||||
method: 'PATCH',
|
||||
@@ -687,7 +694,7 @@ async function updateGameConfigApi(params: {
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json()
|
||||
console.error('[updateGameConfigApi] Server error:', errorData)
|
||||
console.error('[updateGameConfigApi] Server error:', JSON.stringify(errorData, null, 2))
|
||||
throw new Error(errorData.error || 'Failed to update game config')
|
||||
}
|
||||
|
||||
@@ -712,7 +719,10 @@ export function useUpdateGameConfig() {
|
||||
gameConfig: variables.gameConfig,
|
||||
}
|
||||
})
|
||||
console.log('[useUpdateGameConfig] Updated cache with new gameConfig:', variables.gameConfig)
|
||||
console.log(
|
||||
'[useUpdateGameConfig] Updated cache with new gameConfig:',
|
||||
JSON.stringify(variables.gameConfig, null, 2)
|
||||
)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user