feat(notifications): include refresh source in completion and failure logs

Thread options.source through logRefreshSuccess and logRefreshFailure so
WAKEUP_PING and debug-panel refreshes are grep-friendly end-to-end in
Logcat and the Event Log without changing refresh behavior.
This commit is contained in:
Jose Olarte III
2026-06-12 17:12:21 +08:00
parent 3d6ac2ab53
commit 693bfacc1e
2 changed files with 19 additions and 12 deletions

View File

@@ -577,11 +577,12 @@ export async function refreshNotificationsWithDiagnostics(options?: {
source?: string;
}): Promise<RefreshNotificationsResult> {
const startedAt = performance.now();
logRefreshStarted(options?.source);
const source = options?.source;
logRefreshStarted(source);
if (!Capacitor.isNativePlatform()) {
const errorMessage = "not a native platform";
logRefreshFailure(startedAt, errorMessage);
logRefreshFailure(startedAt, errorMessage, undefined, source);
return {
ok: false,
scheduledCount: 0,
@@ -593,7 +594,7 @@ export async function refreshNotificationsWithDiagnostics(options?: {
const auth = await getNotificationApiHeaders("refresh");
if (!auth.ok) {
logSkippingRefreshDueToMissingAuth();
logRefreshFailure(startedAt, auth.message);
logRefreshFailure(startedAt, auth.message, undefined, source);
return {
ok: false,
scheduledCount: 0,
@@ -632,7 +633,7 @@ export async function refreshNotificationsWithDiagnostics(options?: {
statusText: res.statusText,
errorMessage,
});
logRefreshFailure(startedAt, errorMessage, res.status);
logRefreshFailure(startedAt, errorMessage, res.status, source);
return {
ok: false,
scheduledCount: 0,
@@ -647,12 +648,12 @@ export async function refreshNotificationsWithDiagnostics(options?: {
? payload.nextNotifications.length
: 0;
await applyNotificationRefreshPayload(data);
logRefreshSuccess(startedAt, scheduledCount);
logRefreshSuccess(startedAt, scheduledCount, source);
return { ok: true, scheduledCount };
} catch (err) {
logger.error("[NativeNotificationService] Refresh failed", err);
const message = err instanceof Error ? err.message : String(err);
logRefreshFailure(startedAt, message);
logRefreshFailure(startedAt, message, undefined, source);
return { ok: false, scheduledCount: 0, errorMessage: message };
}
}

View File

@@ -85,21 +85,27 @@ function elapsedMsSince(startedAt: number): number {
export function logRefreshSuccess(
startedAt: number,
scheduledCount: number,
source?: string,
): void {
logNotification(
`Refresh completed in ${Math.round(elapsedMsSince(startedAt))}ms (scheduled ${scheduledCount})`,
);
const elapsedMs = Math.round(elapsedMsSince(startedAt));
const message = source
? `Refresh completed (${source}) in ${elapsedMs}ms (scheduled ${scheduledCount})`
: `Refresh completed in ${elapsedMs}ms (scheduled ${scheduledCount})`;
logNotification(message);
}
export function logRefreshFailure(
startedAt: number,
errorMessage: string,
status?: number,
source?: string,
): void {
const statusPart = status != null ? ` HTTP ${status}` : "";
logNotification(
`Refresh failed in ${Math.round(elapsedMsSince(startedAt))}ms: ${errorMessage}${statusPart}`,
);
const elapsedMs = Math.round(elapsedMsSince(startedAt));
const message = source
? `Refresh failed (${source}) in ${elapsedMs}ms: ${errorMessage}${statusPart}`
: `Refresh failed in ${elapsedMs}ms: ${errorMessage}${statusPart}`;
logNotification(message);
}
export function logNotificationClearing(method: string): void {