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

View File

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