Skip to content

Commit 0f08906

Browse files
Make logs more clear (#8991)
1 parent 01ba0d0 commit 0f08906

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/screens/Log.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,21 @@ export function LogScreen({}: NativeStackScreenProps<
8787
) : (
8888
<CircleInfoIcon size="sm" />
8989
)}
90-
<Text style={[a.flex_1]}>{String(entry.message)}</Text>
90+
<View
91+
style={[
92+
a.flex_1,
93+
a.flex_row,
94+
a.justify_start,
95+
a.align_center,
96+
a.gap_sm,
97+
]}>
98+
{entry.context && (
99+
<Text style={[t.atoms.text_contrast_medium]}>
100+
({String(entry.context)})
101+
</Text>
102+
)}
103+
<Text>{String(entry.message)}</Text>
104+
</View>
91105
{entry.metadata &&
92106
Object.keys(entry.metadata).length > 0 &&
93107
(expanded.includes(entry.id) ? (
@@ -115,7 +129,9 @@ export function LogScreen({}: NativeStackScreenProps<
115129
t.atoms.border_contrast_low,
116130
]}>
117131
<View style={[a.px_sm, a.py_xs]}>
118-
<Text>{JSON.stringify(entry.metadata, null, 2)}</Text>
132+
<Text style={[a.leading_snug, {fontFamily: 'monospace'}]}>
133+
{JSON.stringify(entry.metadata, null, 2)}
134+
</Text>
119135
</View>
120136
</View>
121137
)}

src/state/geolocation/config.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function getGeolocationConfig(
2020
})
2121

2222
if (!res.ok) {
23-
throw new Error(`geolocation config: fetch failed ${res.status}`)
23+
throw new Error(`config: fetch failed ${res.status}`)
2424
}
2525

2626
const json = await res.json()
@@ -35,7 +35,7 @@ async function getGeolocationConfig(
3535
ageRestrictedGeos: json.ageRestrictedGeos ?? [],
3636
ageBlockedGeos: json.ageBlockedGeos ?? [],
3737
}
38-
logger.debug(`geolocation config: success`)
38+
logger.debug(`config: success`)
3939
return config
4040
} else {
4141
return undefined
@@ -85,7 +85,7 @@ export function beginResolveGeolocationConfig() {
8585
} catch (e: any) {
8686
success = false
8787

88-
logger.debug(`geolocation config: failed initial request`, {
88+
logger.debug(`config: failed initial request`, {
8989
safeMessage: e.message,
9090
})
9191

@@ -101,12 +101,12 @@ export function beginResolveGeolocationConfig() {
101101
success = true
102102
} else {
103103
// endpoint should throw on all failures, this is insurance
104-
throw new Error(`geolocation config: nothing returned from retries`)
104+
throw new Error(`config: nothing returned from retries`)
105105
}
106106
})
107107
.catch((e: any) => {
108108
// complete fail closed
109-
logger.debug(`geolocation config: failed retries`, {
109+
logger.debug(`config: failed retries`, {
110110
safeMessage: e.message,
111111
})
112112
})
@@ -123,21 +123,19 @@ export function beginResolveGeolocationConfig() {
123123
*/
124124
export async function ensureGeolocationConfigIsResolved() {
125125
if (!geolocationConfigResolution) {
126-
throw new Error(
127-
`geolocation config: beginResolveGeolocationConfig not called yet`,
128-
)
126+
throw new Error(`config: beginResolveGeolocationConfig not called yet`)
129127
}
130128

131129
const cached = device.get(['geolocation'])
132130
if (cached) {
133-
logger.debug(`geolocation config: using cache`)
131+
logger.debug(`config: using cache`)
134132
} else {
135-
logger.debug(`geolocation config: no cache`)
133+
logger.debug(`config: no cache`)
136134
const {success} = await geolocationConfigResolution
137135
if (success) {
138-
logger.debug(`geolocation config: resolved`)
136+
logger.debug(`config: resolved`)
139137
} else {
140-
logger.info(`geolocation config: failed to resolve`)
138+
logger.info(`config: failed to resolve`)
141139
}
142140
}
143141
}

src/state/geolocation/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ export function GeolocationStatusProvider({
9191

9292
const configContext = React.useMemo(() => ({config}), [config])
9393
const statusContext = React.useMemo(() => {
94-
if (deviceGeolocation) {
95-
logger.debug('geolocation: has device geolocation available')
94+
if (deviceGeolocation?.countryCode) {
95+
logger.debug('has device geolocation available')
9696
}
9797
const geolocation = mergeGeolocation(deviceGeolocation, config)
9898
const status = computeGeolocationStatus(geolocation, config)
99+
// ensure this remains debug and never leaves device
100+
logger.debug('result', {deviceGeolocation, geolocation, status, config})
99101
return {location: geolocation, status}
100102
}, [config, deviceGeolocation])
101103

@@ -117,7 +119,7 @@ export function Provider({children}: {children: React.ReactNode}) {
117119

118120
const handleSetDeviceGeolocation = React.useCallback(
119121
(location: DeviceLocation) => {
120-
logger.debug('geolocation: setting device geolocation')
122+
logger.debug('setting device geolocation')
121123
setDeviceGeolocation({
122124
countryCode: location.countryCode ?? undefined,
123125
regionCode: location.regionCode ?? undefined,

0 commit comments

Comments
 (0)