refactor(logging): route frontend console calls through the logger
TRACES: | DR-204 484 ungated `console.*` calls across 63 non-test frontend files shipped to end users with no way to turn them off. Mechanical substitution, no control flow, error handling or message semantics changed: console.log / console.debug -> log.debug console.info -> log.info console.warn -> log.warn console.error -> log.error Hand-written `"[Scope] …"` prefixes are dropped where the logger's scope now carries them; scope names that already existed are preserved verbatim (`[Auth]`, `[VideoPlayer]`, `[PiP]`, …) and inferred from the filename where a file had none. `src/routes/player/[id]/+page.svelte` keeps its `NextEpisode` and `AutoPlay` sub-scopes as separate loggers rather than flattening them into the page scope. `grep -rn 'console\.' src/` now matches nothing outside the tests and the facade itself.
This commit is contained in:
+42
-39
@@ -13,6 +13,9 @@ import type { User, AuthResult } from "$lib/api/types";
|
||||
import type { Session, AuthServerInfo as ServerInfo } from "$lib/api/bindings";
|
||||
import { connectivity } from "./connectivity";
|
||||
import { getDeviceId, clearCache as clearDeviceIdCache } from "$lib/services/deviceId";
|
||||
import { createLogger } from "$lib/utils/logger";
|
||||
|
||||
const log = createLogger("Auth");
|
||||
|
||||
interface AuthState {
|
||||
isAuthenticated: boolean;
|
||||
@@ -70,7 +73,7 @@ function createAuthStore() {
|
||||
|
||||
try {
|
||||
unlistenSessionVerified = await listen<{ user: User }>("auth:session-verified", (event) => {
|
||||
console.log("[Auth] Session verified:", event.payload.user.name);
|
||||
log.debug("Session verified:", event.payload.user.name);
|
||||
update((s) => ({
|
||||
...s,
|
||||
sessionVerified: true,
|
||||
@@ -80,12 +83,12 @@ function createAuthStore() {
|
||||
}));
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("[Auth] Failed to listen to session-verified event:", e);
|
||||
log.error("Failed to listen to session-verified event:", e);
|
||||
}
|
||||
|
||||
try {
|
||||
unlistenNeedsReauth = await listen<{ reason: string }>("auth:needs-reauth", (event) => {
|
||||
console.log("[Auth] Session needs re-authentication:", event.payload.reason);
|
||||
log.debug("Session needs re-authentication:", event.payload.reason);
|
||||
update((s) => ({
|
||||
...s,
|
||||
sessionVerified: false,
|
||||
@@ -95,17 +98,17 @@ function createAuthStore() {
|
||||
}));
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("[Auth] Failed to listen to needs-reauth event:", e);
|
||||
log.error("Failed to listen to needs-reauth event:", e);
|
||||
}
|
||||
|
||||
try {
|
||||
unlistenNetworkError = await listen<{ message: string }>("auth:network-error", (event) => {
|
||||
console.log("[Auth] Network error during verification:", event.payload.message);
|
||||
log.debug("Network error during verification:", event.payload.message);
|
||||
// Network errors don't trigger re-auth - just log them
|
||||
update((s) => ({ ...s, isVerifying: false }));
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("[Auth] Failed to listen to network-error event:", e);
|
||||
log.error("Failed to listen to network-error event:", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +147,7 @@ function createAuthStore() {
|
||||
void (async () => {
|
||||
try {
|
||||
const securityStatus = await commands.storageGetSecurityStatus();
|
||||
console.log("[Auth] Security status:", securityStatus);
|
||||
log.debug("Security status:", securityStatus);
|
||||
if (!securityStatus.usingKeyring) {
|
||||
update((s) => ({
|
||||
...s,
|
||||
@@ -153,17 +156,17 @@ function createAuthStore() {
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("[Auth] Failed to get security status:", error);
|
||||
log.warn("Failed to get security status:", error);
|
||||
}
|
||||
})();
|
||||
|
||||
// Initialize auth manager and get session
|
||||
console.log("[Auth] Initializing auth manager...");
|
||||
log.debug("Initializing auth manager...");
|
||||
const session = await commands.authInitialize();
|
||||
console.log("[Auth] Session retrieval result:", session ? "Session found" : "No session found");
|
||||
log.debug("Session retrieval result:", session ? "Session found" : "No session found");
|
||||
|
||||
if (session) {
|
||||
console.log("[Auth] Restoring session for user:", session.username, "on server:", session.serverUrl);
|
||||
log.debug("Restoring session for user:", session.username, "on server:", session.serverUrl);
|
||||
|
||||
// Create RepositoryClient for cache-first access. This IS required before
|
||||
// we mark authenticated — the first screen (library overview) reads
|
||||
@@ -184,9 +187,9 @@ function createAuthStore() {
|
||||
session.userId,
|
||||
deviceId
|
||||
);
|
||||
console.log("[Auth] Rust player configured for automatic playback reporting");
|
||||
log.debug("Rust player configured for automatic playback reporting");
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to configure Rust player:", error);
|
||||
log.error("Failed to configure Rust player:", error);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -205,7 +208,7 @@ function createAuthStore() {
|
||||
});
|
||||
|
||||
// Start connectivity monitoring early to avoid appearing offline on startup
|
||||
console.log("[Auth] Starting early connectivity monitoring...");
|
||||
log.debug("Starting early connectivity monitoring...");
|
||||
connectivity.startMonitoring(session.serverUrl, {
|
||||
onServerReconnected: () => {
|
||||
// Retry session verification when server becomes reachable
|
||||
@@ -214,10 +217,10 @@ function createAuthStore() {
|
||||
// Lazy import to avoid an auth <-> offlineCatalog import cycle.
|
||||
import("$lib/services/offlineCatalog")
|
||||
.then((m) => m.onReconnected())
|
||||
.catch((err) => console.warn("[Auth] Catalog reconnect failed:", err));
|
||||
.catch((err) => log.warn("Catalog reconnect failed:", err));
|
||||
},
|
||||
}).catch((error) => {
|
||||
console.error("[Auth] Failed to start connectivity monitoring:", error);
|
||||
log.error("Failed to start connectivity monitoring:", error);
|
||||
});
|
||||
|
||||
// Start background session verification — fire-and-forget. This is
|
||||
@@ -228,14 +231,14 @@ function createAuthStore() {
|
||||
try {
|
||||
const verifyDeviceId = await getDeviceId();
|
||||
await commands.authStartVerification(verifyDeviceId);
|
||||
console.log("[Auth] Background verification started");
|
||||
log.debug("Background verification started");
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to start verification:", error);
|
||||
log.error("Failed to start verification:", error);
|
||||
}
|
||||
})();
|
||||
} else {
|
||||
// No stored session
|
||||
console.log("[Auth] No active session found");
|
||||
log.debug("No active session found");
|
||||
set({
|
||||
isAuthenticated: false,
|
||||
isLoading: false,
|
||||
@@ -250,7 +253,7 @@ function createAuthStore() {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to initialize:", error);
|
||||
log.error("Failed to initialize:", error);
|
||||
update((s) => ({
|
||||
...s,
|
||||
isLoading: false,
|
||||
@@ -269,15 +272,15 @@ function createAuthStore() {
|
||||
update((s) => ({ ...s, isLoading: true, error: null }));
|
||||
|
||||
try {
|
||||
console.log("[Auth] Connecting to server:", serverUrl);
|
||||
log.debug("Connecting to server:", serverUrl);
|
||||
const serverInfo = await commands.authConnectToServer(serverUrl);
|
||||
console.log("[Auth] Connected to server:", serverInfo.name, serverInfo.version);
|
||||
console.log("[Auth] Normalized URL:", serverInfo.normalizedUrl);
|
||||
log.debug("Connected to server:", serverInfo.name, serverInfo.version);
|
||||
log.debug("Normalized URL:", serverInfo.normalizedUrl);
|
||||
|
||||
update((s) => ({ ...s, isLoading: false }));
|
||||
return serverInfo;
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to connect to server:", error);
|
||||
log.error("Failed to connect to server:", error);
|
||||
update((s) => ({
|
||||
...s,
|
||||
isLoading: false,
|
||||
@@ -297,11 +300,11 @@ function createAuthStore() {
|
||||
|
||||
try {
|
||||
const deviceId = await getDeviceId();
|
||||
console.log("[Auth] Logging in as:", username);
|
||||
log.debug("Logging in as:", username);
|
||||
|
||||
const authResult = await commands.authLogin(serverUrl, username, password, deviceId);
|
||||
|
||||
console.log("[Auth] Login successful:", authResult.user);
|
||||
log.debug("Login successful:", authResult.user);
|
||||
|
||||
// Save to storage
|
||||
await commands.storageSaveServer(authResult.serverId, serverName, serverUrl, null);
|
||||
@@ -340,9 +343,9 @@ function createAuthStore() {
|
||||
authResult.user.id,
|
||||
playerDeviceId
|
||||
);
|
||||
console.log("[Auth] Rust player configured for playback reporting");
|
||||
log.debug("Rust player configured for playback reporting");
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to configure Rust player:", error);
|
||||
log.error("Failed to configure Rust player:", error);
|
||||
}
|
||||
|
||||
// Update state
|
||||
@@ -364,12 +367,12 @@ function createAuthStore() {
|
||||
const verifyDeviceId = await getDeviceId();
|
||||
await commands.authStartVerification(verifyDeviceId);
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to start verification:", error);
|
||||
log.error("Failed to start verification:", error);
|
||||
}
|
||||
|
||||
return authResult;
|
||||
} catch (error) {
|
||||
console.error("[Auth] Login failed:", error);
|
||||
log.error("Login failed:", error);
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
update((s) => ({ ...s, isLoading: false, error: errorMessage }));
|
||||
throw error;
|
||||
@@ -384,11 +387,11 @@ function createAuthStore() {
|
||||
|
||||
try {
|
||||
const deviceId = await getDeviceId();
|
||||
console.log("[Auth] Re-authenticating...");
|
||||
log.debug("Re-authenticating...");
|
||||
|
||||
const authResult = await commands.authReauthenticate(password, deviceId);
|
||||
|
||||
console.log("[Auth] Re-authentication successful");
|
||||
log.debug("Re-authentication successful");
|
||||
|
||||
// Update storage
|
||||
await commands.storageSaveUser(
|
||||
@@ -417,7 +420,7 @@ function createAuthStore() {
|
||||
playerDeviceId
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to reconfigure player:", error);
|
||||
log.error("Failed to reconfigure player:", error);
|
||||
}
|
||||
|
||||
// Update state
|
||||
@@ -432,7 +435,7 @@ function createAuthStore() {
|
||||
|
||||
return authResult;
|
||||
} catch (error) {
|
||||
console.error("[Auth] Re-authentication failed:", error);
|
||||
log.error("Re-authentication failed:", error);
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
update((s) => ({ ...s, isLoading: false, error: errorMessage }));
|
||||
throw error;
|
||||
@@ -456,7 +459,7 @@ function createAuthStore() {
|
||||
try {
|
||||
await commands.playerDisableJellyfin();
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to disable player reporting:", error);
|
||||
log.error("Failed to disable player reporting:", error);
|
||||
}
|
||||
|
||||
// Clear repository
|
||||
@@ -481,7 +484,7 @@ function createAuthStore() {
|
||||
// Clear device ID cache on logout
|
||||
clearDeviceIdCache();
|
||||
} catch (error) {
|
||||
console.error("[Auth] Logout error (continuing anyway):", error);
|
||||
log.error("Logout error (continuing anyway):", error);
|
||||
set(initialState);
|
||||
clearDeviceIdCache();
|
||||
}
|
||||
@@ -501,7 +504,7 @@ function createAuthStore() {
|
||||
try {
|
||||
return await commands.authGetSession();
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to get current session:", error);
|
||||
log.error("Failed to get current session:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -536,10 +539,10 @@ function createAuthStore() {
|
||||
async function retryVerification() {
|
||||
try {
|
||||
const deviceId = await getDeviceId();
|
||||
console.log("[Auth] Retrying session verification after reconnection");
|
||||
log.debug("Retrying session verification after reconnection");
|
||||
await commands.authStartVerification(deviceId);
|
||||
} catch (error) {
|
||||
console.error("[Auth] Failed to retry verification:", error);
|
||||
log.error("Failed to retry verification:", error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user