From 0a09aac0d3445c91996603f52c253fbe9b4e22f4 Mon Sep 17 00:00:00 2001 From: Seth Etter Date: Sun, 30 Aug 2026 08:13:49 -0500 Subject: [PATCH] Use structured logger instead of console.log --- package-lock.json | 3 ++- package.json | 3 ++- src/main.ts | 2 +- src/slack/slack.ts | 7 ++++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index aafdffc..ca681e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ "@opentelemetry/sdk-node": "^0.221.0", "@slack/web-api": "^7.18.0", "fastify": "^5.9.0", - "json-schema-to-ts": "^3.1.1" + "json-schema-to-ts": "^3.1.1", + "pino": "^10.3.1" }, "devDependencies": { "@kubb/plugin-fetch": "^5.0.0-beta.94", diff --git a/package.json b/package.json index 802210e..c76df69 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "@opentelemetry/sdk-node": "^0.221.0", "@slack/web-api": "^7.18.0", "fastify": "^5.9.0", - "json-schema-to-ts": "^3.1.1" + "json-schema-to-ts": "^3.1.1", + "pino": "^10.3.1" }, "devDependencies": { "@kubb/plugin-fetch": "^5.0.0-beta.94", diff --git a/src/main.ts b/src/main.ts index 6944ec5..b12b3bf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,7 @@ const app = buildServer({ try { await app.listen({ port: 3000, host: "0.0.0.0" }); - console.log("devict-bot listening on :3000"); + app.log.info("devict-bot listening on :3000"); } catch (err) { await app.close(); throw err; diff --git a/src/slack/slack.ts b/src/slack/slack.ts index a439296..5d51871 100644 --- a/src/slack/slack.ts +++ b/src/slack/slack.ts @@ -1,4 +1,5 @@ import { WebClient } from "@slack/web-api"; +import { pino } from "pino"; import { withSpan } from "../telemetry.ts"; import { verifySlackSignature } from "./signature.ts"; @@ -20,6 +21,10 @@ export interface SlackClientDeps { signingSecret: string; } +// Standalone logger: the slack client is constructed before the fastify app +// (and its logger) exists. Matches fastify's default pino JSON output. +const log = pino(); + export function makeSlackClient({ botToken, adminToken, @@ -40,7 +45,7 @@ export function makeSlackClient({ // a bot-auth'd request like the rest. async inviteUser({ email }): Promise { await withSpan("slack.inviteUser", { "slack.invite.email": email }, async () => { - console.log(`Inviting: ${email}`); + log.info({ email }, "slack: inviting user"); const url = `https://devict.slack.com/api/users.admin.invite?t=${Date.now()}`; const resp = await fetch(url, { -- 2.51.2