feat: add structured backend logging
CI / Static checks (push) Successful in 37s
CI / Build and push image (push) Skipped

Collector failures, service-API errors, WS connection lifecycle, and
config reload/discovery events were previously invisible outside the
browser (or, for a few config/discovery cases, logged with an
inconsistent ad-hoc console.error). Add a small scoped logger
(lib/logger.ts, level via LOG_LEVEL) and wire it through server.ts,
the scheduler, service collector, config loader/effective store, and
the WS server so operators can see failures via `docker logs`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-19 09:39:30 +02:00
co-authored by Claude Sonnet 5
parent 94ffa9e930
commit 7727ca8e97
7 changed files with 159 additions and 18 deletions
+8 -4
View File
@@ -8,6 +8,9 @@ import { collectN8n } from "./services/n8n";
import { collectUmami } from "./services/umami";
import { collectHeadscale } from "./services/headscale";
import { collectTraefikStat } from "./services/traefik";
import { createLogger } from "@/lib/logger";
const log = createLogger("service");
function collectServiceStat(widget: ServiceWidget): Promise<{ stats: ServiceStat[] }> {
switch (widget.service) {
@@ -34,10 +37,11 @@ export async function collectService(widget: ServiceWidget): Promise<ServiceWidg
// A failed service-API call (bad token, service down) must not take out the
// docker health readout too - the two are independent failure modes and
// merging them into one card should not let one mask the other.
const statPromise = collectServiceStat(widget).catch((err) => ({
stats: [] as ServiceStat[],
statError: (err as Error).message,
}));
const statPromise = collectServiceStat(widget).catch((err) => {
const message = (err as Error).message;
log.warn("service API call failed", { service: widget.service, containerName: widget.containerName, error: message });
return { stats: [] as ServiceStat[], statError: message };
});
const [docker, statResult] = await Promise.all([dockerPromise, statPromise]);
return { docker, ...statResult };