Skip to content

Commit f41fe72

Browse files
committed
refactor: standardize logging messages across multiple services for clarity and consistency
1 parent d061abb commit f41fe72

File tree

12 files changed

+48
-63
lines changed

12 files changed

+48
-63
lines changed

lib/schedule.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function scheduleRevalidation(
6363

6464
// Check if domain should stop being revalidated due to inactivity
6565
if (shouldStopRevalidation(section, lastAccessedAt ?? null)) {
66-
logger.info(`skip ${section} ${normalizedDomain} (stopped: inactive)`, {
66+
logger.info("skip (stopped: inactive)", {
6767
domain: normalizedDomain,
6868
section,
6969
lastAccessedAt: lastAccessedAt?.toISOString() ?? "never",
@@ -85,7 +85,7 @@ export async function scheduleRevalidation(
8585
const daysInactive = lastAccessedAt
8686
? Math.floor((now - lastAccessedAt.getTime()) / (1000 * 60 * 60 * 24))
8787
: null;
88-
logger.info(`decay ${section} ${normalizedDomain}`, {
88+
logger.info("decay set", {
8989
domain: normalizedDomain,
9090
section,
9191
decayMultiplier,
@@ -120,14 +120,14 @@ export async function scheduleRevalidation(
120120
id: eventId,
121121
});
122122

123-
logger.debug(`ok ${section} ${normalizedDomain}`, {
123+
logger.debug("done", {
124124
domain: normalizedDomain,
125125
section,
126126
scheduledAt: new Date(scheduledDueMs).toISOString(),
127127
});
128128
return true;
129129
} catch (err) {
130-
logger.error(`failed ${section} ${normalizedDomain}`, err, {
130+
logger.error("unexpected failure", err, {
131131
domain: normalizedDomain,
132132
section,
133133
});

lib/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function uploadWithRetry(
6969
cacheControlMaxAge,
7070
});
7171

72-
logger.info(`upload ok ${pathname}`, {
72+
logger.info("upload ok", {
7373
pathname,
7474
attempts: attempt + 1,
7575
});

server/services/certificates.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ttlForCertificates } from "@/lib/ttl";
1919
const logger = createLogger({ source: "certificates" });
2020

2121
export async function getCertificates(domain: string): Promise<Certificate[]> {
22-
logger.debug(`start ${domain}`, { domain });
22+
logger.debug("start", { domain });
2323

2424
// Only support registrable domains (no subdomains, IPs, or invalid TLDs)
2525
const registrable = toRegistrableDomain(domain);
@@ -67,7 +67,7 @@ export async function getCertificates(domain: string): Promise<Certificate[]> {
6767
caProvider: detectCertificateAuthority(c.issuer),
6868
}));
6969

70-
logger.info(`cache hit ${registrable}`, {
70+
logger.info("cache hit", {
7171
domain: registrable,
7272
count: out.length,
7373
cached: true,
@@ -189,13 +189,13 @@ export async function getCertificates(domain: string): Promise<Certificate[]> {
189189
});
190190
}
191191

192-
logger.info(`ok ${registrable}`, {
192+
logger.info("done", {
193193
domain: registrable,
194194
chainLength: out.length,
195195
});
196196
return out;
197197
} catch (err) {
198-
logger.error(`error ${registrable}`, err, { domain: registrable });
198+
logger.error("probe failed", err, { domain: registrable });
199199
// Do not treat as fatal; return empty and avoid long-lived negative cache
200200
return [];
201201
}

server/services/dns.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function buildDohUrl(
8484
export const resolveAll = cache(async function resolveAll(
8585
domain: string,
8686
): Promise<DnsResolveResult> {
87-
logger.debug(`start ${domain}`, { domain });
87+
logger.debug("start", { domain });
8888

8989
const providers = providerOrderForLookup(domain);
9090
const durationByProvider: Record<string, number> = {};
@@ -170,7 +170,7 @@ export const resolveAll = cache(async function resolveAll(
170170
const deduplicated = deduplicateDnsRecords(assembled);
171171
const sorted = sortDnsRecordsByType(deduplicated, types);
172172
if (allFreshAcrossTypes) {
173-
logger.info(`cache hit ${registrable}`, {
173+
logger.info("cache hit", {
174174
domain: registrable,
175175
types: freshTypes.join(","),
176176
cached: true,
@@ -284,7 +284,7 @@ export const resolveAll = cache(async function resolveAll(
284284
{ A: 0, AAAA: 0, MX: 0, TXT: 0, NS: 0 } as Record<DnsType, number>,
285285
);
286286

287-
logger.info(`ok partial ${registrable}`, {
287+
logger.info("partial refresh done", {
288288
domain: registrable,
289289
counts,
290290
resolver: pinnedProvider.key,
@@ -391,7 +391,7 @@ export const resolveAll = cache(async function resolveAll(
391391
});
392392
});
393393
}
394-
logger.info(`ok ${registrable}`, {
394+
logger.info("done", {
395395
domain: registrable,
396396
counts,
397397
resolver: resolverUsed,
@@ -403,7 +403,7 @@ export const resolveAll = cache(async function resolveAll(
403403
const sorted = sortDnsRecordsByType(deduplicated, types);
404404
return { records: sorted, resolver: resolverUsed } as DnsResolveResult;
405405
} catch (err) {
406-
logger.warn(`provider attempt failed ${registrable}`, {
406+
logger.warn("provider attempt failed", {
407407
domain: registrable,
408408
provider: provider.key,
409409
});
@@ -417,7 +417,7 @@ export const resolveAll = cache(async function resolveAll(
417417
const error = new Error(
418418
`All DoH providers failed for ${registrable}: ${String(lastError)}`,
419419
);
420-
logger.error(`all providers failed ${registrable}`, error, {
420+
logger.error("all providers failed", error, {
421421
domain: registrable,
422422
providers: providers.map((p) => p.key).join(","),
423423
});

server/services/favicon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async function fetchFaviconInternal(
6060
// Safety: Auto-cleanup stale promise after timeout
6161
const timeoutId = setTimeout(() => {
6262
if (faviconPromises.get(registrable) === promise) {
63-
logger.warn(`cleaning up stale promise for ${registrable}`, {
63+
logger.warn("cleaning up stale promise", {
6464
domain: registrable,
6565
timeoutMs: PROMISE_CLEANUP_TIMEOUT_MS,
6666
});

server/services/headers.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const probeHeaders = cache(async function probeHeaders(
2727
domain: string,
2828
): Promise<HttpHeadersResponse> {
2929
const url = `https://${domain}/`;
30-
logger.debug(`start ${domain}`, { domain });
30+
logger.debug("start", { domain });
3131

3232
// Only support registrable domains (no subdomains, IPs, or invalid TLDs)
3333
const registrable = toRegistrableDomain(domain);
@@ -65,7 +65,7 @@ export const probeHeaders = cache(async function probeHeaders(
6565
statusMessage = undefined;
6666
}
6767

68-
logger.info(`cache hit ${registrable}`, {
68+
logger.info("cache hit", {
6969
domain: registrable,
7070
status: row.status,
7171
count: normalized.length,
@@ -116,7 +116,7 @@ export const probeHeaders = cache(async function probeHeaders(
116116
});
117117
});
118118
}
119-
logger.info(`ok ${registrable}`, {
119+
logger.info("done", {
120120
domain: registrable,
121121
status: final.status,
122122
count: normalized.length,
@@ -137,11 +137,11 @@ export const probeHeaders = cache(async function probeHeaders(
137137
const isDnsError = isExpectedDnsError(err);
138138

139139
if (isDnsError) {
140-
logger.debug(`no web hosting ${registrable} (no A/AAAA records)`, {
140+
logger.debug("no web hosting (no A/AAAA records)", {
141141
domain: registrable,
142142
});
143143
} else {
144-
logger.error(`error ${registrable}`, err, { domain: registrable });
144+
logger.error("probe failed", err, { domain: registrable });
145145
}
146146

147147
// Return empty on failure without caching to avoid long-lived negatives

server/services/hosting.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const logger = createLogger({ source: "hosting" });
3939
export const detectHosting = cache(async function detectHosting(
4040
domain: string,
4141
): Promise<Hosting> {
42-
logger.debug(`start ${domain}`, { domain });
42+
logger.debug("start", { domain });
4343

4444
// Only support registrable domains (no subdomains, IPs, or invalid TLDs)
4545
const registrable = toRegistrableDomain(domain);
@@ -103,7 +103,7 @@ export const detectHosting = cache(async function detectHosting(
103103
lon: row.geoLon ?? null,
104104
},
105105
};
106-
logger.info(`cache hit ${domain}`, {
106+
logger.info("cache hit", {
107107
domain,
108108
hosting: info.hostingProvider.name,
109109
email: info.emailProvider.name,
@@ -126,7 +126,7 @@ export const detectHosting = cache(async function detectHosting(
126126
const [headersResponse, meta] = await Promise.all([
127127
hasWebHosting
128128
? probeHeaders(domain).catch((err) => {
129-
logger.error(`headers probe error ${domain}`, err, { domain });
129+
logger.error("headers probe error", err, { domain });
130130
return {
131131
headers: [] as { name: string; value: string }[],
132132
status: 0,
@@ -284,11 +284,13 @@ export const detectHosting = cache(async function detectHosting(
284284
});
285285
});
286286
}
287-
logger.info(`ok ${registrable}`, {
287+
288+
logger.info("done", {
288289
domain: registrable,
289290
hosting: hostingName,
290291
email: emailName,
291292
dns: dnsName,
292293
});
294+
293295
return info;
294296
});

server/services/ip.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export const lookupIpMeta = cache(async function lookupIpMeta(
2424
owner: string | null;
2525
domain: string | null;
2626
}> {
27-
logger.debug(`start lookup for ${ip}`, { type: "ip" });
27+
logger.debug("start", { ip });
28+
2829
try {
2930
// Add timeout to prevent hanging requests to upstream IP service
3031
const controller = new AbortController();
@@ -37,8 +38,8 @@ export const lookupIpMeta = cache(async function lookupIpMeta(
3738
clearTimeout(timeoutId);
3839

3940
if (!res.ok) {
40-
logger.error(`error looking up ${ip}`, undefined, {
41-
type: "ip",
41+
logger.error("lookup failed", undefined, {
42+
ip,
4243
status: res.status,
4344
statusMessage: res.statusText,
4445
});
@@ -98,8 +99,8 @@ export const lookupIpMeta = cache(async function lookupIpMeta(
9899
lon: typeof data.longitude === "number" ? data.longitude : null,
99100
};
100101

101-
logger.info(`ok ${ip}`, {
102-
type: "ip",
102+
logger.info("done", {
103+
ip,
103104
owner: owner || "none",
104105
domain: domain || "none",
105106
});
@@ -111,7 +112,7 @@ export const lookupIpMeta = cache(async function lookupIpMeta(
111112
throw fetchErr;
112113
}
113114
} catch (err) {
114-
logger.error(`error looking up ${ip}`, err, { type: "ip" });
115+
logger.error("lookup failed", err, { ip });
115116
return {
116117
owner: null,
117118
domain: null,

server/services/pricing.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ async function fetchProviderPricing(
5151
): Promise<RegistrarPricingResponse | null> {
5252
try {
5353
const payload = await provider.fetchPricing();
54-
logger.info(`fetch ok ${provider.name}`, { provider: provider.name });
54+
logger.info("fetch ok", { provider: provider.name });
5555
return payload;
5656
} catch (err) {
57-
logger.error(`fetch error ${provider.name}`, err, {
58-
provider: provider.name,
59-
});
57+
logger.error("fetch error", err, { provider: provider.name });
6058
return null;
6159
}
6260
}
@@ -90,7 +88,7 @@ const porkbunProvider: PricingProvider = {
9088
);
9189

9290
if (!res.ok) {
93-
logger.error(`upstream error porkbun status=${res.status}`, undefined, {
91+
logger.error("upstream error", undefined, {
9492
provider: "porkbun",
9593
status: res.status,
9694
});
@@ -139,14 +137,10 @@ const cloudflareProvider: PricingProvider = {
139137
});
140138

141139
if (!res.ok) {
142-
logger.error(
143-
`upstream error cloudflare status=${res.status}`,
144-
undefined,
145-
{
146-
provider: "cloudflare",
147-
status: res.status,
148-
},
149-
);
140+
logger.error("upstream error", undefined, {
141+
provider: "cloudflare",
142+
status: res.status,
143+
});
150144
throw new Error(`Cloudflare pricing API returned ${res.status}`);
151145
}
152146

server/services/registration.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function normalizeRegistrar(registrar?: { name?: unknown; url?: unknown }): {
5555
* Fetch domain registration using rdapper and cache the normalized DomainRecord.
5656
*/
5757
export async function getRegistration(domain: string): Promise<Registration> {
58-
logger.debug(`start ${domain}`, { domain });
58+
logger.debug("start", { domain });
5959

6060
// Only support registrable domains (no subdomains, IPs, or invalid TLDs)
6161
const registrable = toRegistrableDomain(domain);
@@ -132,12 +132,7 @@ export async function getRegistration(domain: string): Promise<Registration> {
132132
});
133133
});
134134

135-
logger.info(`ok cached ${registrable}`, {
136-
domain: registrable,
137-
isRegistered: row.registration.isRegistered,
138-
registrar: registrarProvider.name,
139-
cached: true,
140-
});
135+
logger.info("cache hit", { domain: registrable });
141136

142137
return response;
143138
}
@@ -185,10 +180,7 @@ export async function getRegistration(domain: string): Promise<Registration> {
185180

186181
// If unregistered, return response without persisting to Postgres
187182
if (!record.isRegistered) {
188-
logger.info(`ok ${registrable} unregistered (not persisted)`, {
189-
domain: registrable,
190-
isRegistered: false,
191-
});
183+
logger.info("unregistered (not persisted)", { domain: registrable });
192184

193185
const registrarProvider = normalizeRegistrar(record.registrar ?? {});
194186

@@ -311,11 +303,7 @@ export async function getRegistration(domain: string): Promise<Registration> {
311303
});
312304
});
313305

314-
logger.info(`ok ${registrable}`, {
315-
domain: registrable,
316-
isRegistered: record.isRegistered,
317-
registrar: withProvider.registrarProvider.name,
318-
});
306+
logger.info("done", { domain: registrable });
319307

320308
return withProvider;
321309
}

0 commit comments

Comments
 (0)