From 783752719d5662f2182e8ba6adabfe49b7f85326 Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 30 Nov 2026 03:09:29 +0200 Subject: [PATCH 1/5] feat: proxy logs to discord --- .env.example | 1 + .env.production | 1 + src/constants/channels.ts | 2 ++ src/env.ts | 1 + src/util/logger.ts | 10 ++++++++-- 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index f8e204a..13fab63 100644 --- a/.env.example +++ b/.env.example @@ -13,6 +13,7 @@ ONBOARDING_CHANNEL_ID=onboarding_channel_id_here SPAM_DETECTION_CHANNEL_ID=spam_detection_channel_id_here ARCHIVE_CATEGORY_ID=archive_category_id_here SHOWCASE_DIGEST_CHANNEL_ID=showcase_digest_channel_id_here +BOT_LOGS_CHANNEL_ID=bot_logs_channel_id_here # Role IDs (REQUIRED) MODERATORS_ROLE_IDS=role_id_1,role_id_2,role_id_3 diff --git a/.env.production b/.env.production index bf2c30f..d986cf0 100644 --- a/.env.production +++ b/.env.production @@ -15,6 +15,7 @@ SHOWCASE_RULES_CHANNEL_ID=1517948527098073158 SPAM_DETECTION_CHANNEL_ID=973895712314110032 ARCHIVE_CATEGORY_ID=837507969859977258 SHOWCASE_DIGEST_CHANNEL_ID=1561474075745059017 +BOT_LOGS_CHANNEL_ID=1576765207697686699 # Role IDs (from your dev server) REPEL_ROLE_ID=1002411741776461844 diff --git a/src/constants/channels.ts b/src/constants/channels.ts index 000489a..2b95063 100644 --- a/src/constants/channels.ts +++ b/src/constants/channels.ts @@ -19,6 +19,7 @@ type ChannelTypeMap = { showcaseDigest: TextChannel; spamDetection: TextChannel; archiveCategory: CategoryChannel; + botLogs: TextChannel; }; const EXPECTED_DISCORD_TYPE: Record = { @@ -31,6 +32,7 @@ const EXPECTED_DISCORD_TYPE: Record = { showcaseDigest: ChannelType.GuildText, spamDetection: ChannelType.GuildText, archiveCategory: ChannelType.GuildCategory, + botLogs: ChannelType.GuildText, }; const resolveChannel = ( diff --git a/src/env.ts b/src/env.ts index 80de945..a723758 100644 --- a/src/env.ts +++ b/src/env.ts @@ -49,6 +49,7 @@ export const config = { showcaseDigest: requireEnv('SHOWCASE_DIGEST_CHANNEL_ID'), spamDetection: requireEnv('SPAM_DETECTION_CHANNEL_ID'), archiveCategory: requireEnv('ARCHIVE_CATEGORY_ID'), + botLogs: requireEnv('BOT_LOGS_CHANNEL_ID'), }, onboarding: { channelId: optionalEnv('ONBOARDING_CHANNEL_ID'), diff --git a/src/util/logger.ts b/src/util/logger.ts index 48eea37..ca7baf8 100644 --- a/src/util/logger.ts +++ b/src/util/logger.ts @@ -1,3 +1,5 @@ +import { SERVER_CHANNELS } from '@/constants/channels.js'; + const logMethod = { info: 'INFO', warn: 'WARN', @@ -18,11 +20,15 @@ export const createLogger = (feature: string): Logger => { return Object.fromEntries( Object.entries(logMethod).map(([method, level]) => [ method, - (...messages: unknown[]) => + (...messages: unknown[]) => { console[method as keyof Logger]( buildPrefix(feature, level), ...messages - ), + ); + void SERVER_CHANNELS.botLogs?.send( + `${buildPrefix(feature, level)} ${messages.join(' ')}` + ); + }, ]) ) as Logger; }; From bff867045f2630af01016965c1f33d53a80f3659 Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 30 Nov 2026 03:17:12 +0200 Subject: [PATCH 2/5] fix: break logger dependency cycle during Prisma startup --- src/constants/channels.ts | 2 ++ src/util/logger.test.ts | 17 ++++++++++++++++- src/util/logger.ts | 14 +++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/constants/channels.ts b/src/constants/channels.ts index 2b95063..41b554a 100644 --- a/src/constants/channels.ts +++ b/src/constants/channels.ts @@ -6,6 +6,7 @@ import type { } from 'discord.js'; import { ChannelType } from 'discord.js'; import { config } from '@/env.js'; +import { setLogChannel } from '@/util/logger.js'; export type ChannelKey = keyof typeof config.channelIds; @@ -73,4 +74,5 @@ export const resolveChannels = (guild: Guild): void => { (Object.keys(config.channelIds) as ChannelKey[]).forEach((key) => { assignResolvedChannel(key, resolveChannel(guild, key)); }); + setLogChannel(SERVER_CHANNELS.botLogs); }; diff --git a/src/util/logger.test.ts b/src/util/logger.test.ts index 48b5ca9..0286c1f 100644 --- a/src/util/logger.test.ts +++ b/src/util/logger.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { afterEach, describe, it, mock } from 'node:test'; -import { createLogger } from './logger.js'; +import { createLogger, setLogChannel } from './logger.js'; const buildPrefixRegex = (feature: string, level: string) => new RegExp( @@ -9,6 +9,7 @@ const buildPrefixRegex = (feature: string, level: string) => void describe('createLogger', () => { afterEach(() => { + setLogChannel(undefined); mock.restoreAll(); }); @@ -45,4 +46,18 @@ void describe('createLogger', () => { assert.match(prefix as string, buildPrefixRegex('tags', 'ERROR')); assert.deepEqual(messages, ['Error deleting tag:', error]); }); + + void it('forwards logs to the configured channel', () => { + mock.method(console, 'info', () => {}); + const send = mock.fn(async (_message: string) => {}); + setLogChannel({ send }); + + createLogger('guides').info('synced', 42); + + assert.equal(send.mock.calls.length, 1); + assert.match( + send.mock.calls[0]!.arguments[0], + /^\[.*\] \[guides\] \[INFO\] synced 42$/ + ); + }); }); diff --git a/src/util/logger.ts b/src/util/logger.ts index ca7baf8..2b4837f 100644 --- a/src/util/logger.ts +++ b/src/util/logger.ts @@ -1,5 +1,3 @@ -import { SERVER_CHANNELS } from '@/constants/channels.js'; - const logMethod = { info: 'INFO', warn: 'WARN', @@ -13,6 +11,16 @@ type Logger = { [K in keyof typeof logMethod]: (...messages: unknown[]) => void; }; +type LogChannel = { + send: (message: string) => Promise; +}; + +let logChannel: LogChannel | undefined; + +export const setLogChannel = (channel: LogChannel | undefined): void => { + logChannel = channel; +}; + /** * Every line is prefixed with `[feature]` so logs can be filtered by feature name. */ @@ -25,7 +33,7 @@ export const createLogger = (feature: string): Logger => { buildPrefix(feature, level), ...messages ); - void SERVER_CHANNELS.botLogs?.send( + void logChannel?.send( `${buildPrefix(feature, level)} ${messages.join(' ')}` ); }, From 03aae563722612b9fb00f6c1631328211e83d432 Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 30 Nov 2026 03:21:10 +0200 Subject: [PATCH 3/5] test: add missing env --- .env.test | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.test b/.env.test index 22fc81b..ac3b9de 100644 --- a/.env.test +++ b/.env.test @@ -22,6 +22,7 @@ SHOWCASE_RULES_CHANNEL_ID=your-showcase-rules-channel-id SPAM_DETECTION_CHANNEL_ID=spam-detection-channel-id-here ARCHIVE_CATEGORY_ID=your-archived-category-id SHOWCASE_DIGEST_CHANNEL_ID=your-showcase-digest-channel-id +BOT_LOG_CHANNEL_ID=your-bot-log-channel-id # Role IDs (from your dev server) REPEL_ROLE_ID=your-repel-role-id From 1d3e1a52cd6b7a760d5f60efc8357262b347fb78 Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 30 Nov 2026 03:21:10 +0200 Subject: [PATCH 4/5] test: add missing env --- .env.test | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.test b/.env.test index 22fc81b..8bcc3fa 100644 --- a/.env.test +++ b/.env.test @@ -22,6 +22,7 @@ SHOWCASE_RULES_CHANNEL_ID=your-showcase-rules-channel-id SPAM_DETECTION_CHANNEL_ID=spam-detection-channel-id-here ARCHIVE_CATEGORY_ID=your-archived-category-id SHOWCASE_DIGEST_CHANNEL_ID=your-showcase-digest-channel-id +BOT_LOGS_CHANNEL_ID=your-bot-log-channel-id # Role IDs (from your dev server) REPEL_ROLE_ID=your-repel-role-id From f0240888ada2a1a29329a2e88efe9836cf687b7e Mon Sep 17 00:00:00 2001 From: Ali Hammoud Date: Mon, 30 Nov 2026 03:35:30 +0200 Subject: [PATCH 5/5] test: add missing env --- .env.test | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.env.test b/.env.test index 7a6457a..8bcc3fa 100644 --- a/.env.test +++ b/.env.test @@ -22,11 +22,7 @@ SHOWCASE_RULES_CHANNEL_ID=your-showcase-rules-channel-id SPAM_DETECTION_CHANNEL_ID=spam-detection-channel-id-here ARCHIVE_CATEGORY_ID=your-archived-category-id SHOWCASE_DIGEST_CHANNEL_ID=your-showcase-digest-channel-id -<<<<<<< HEAD BOT_LOGS_CHANNEL_ID=your-bot-log-channel-id -======= -BOT_LOG_CHANNEL_ID=your-bot-log-channel-id ->>>>>>> 03aae563722612b9fb00f6c1631328211e83d432 # Role IDs (from your dev server) REPEL_ROLE_ID=your-repel-role-id