From b473898cef1640b83b00f91d7f6940caea7fd96c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 30 Jan 2025 01:43:57 -0600 Subject: [PATCH] Upgrade Logi --- deno.json | 2 +- deno.lock | 8 ++++---- src/db/KyselyLogger.ts | 7 +++---- src/startup.ts | 17 ----------------- src/utils/log.ts | 10 ++++------ 5 files changed, 12 insertions(+), 32 deletions(-) diff --git a/deno.json b/deno.json index 40668402..4996439c 100644 --- a/deno.json +++ b/deno.json @@ -52,7 +52,7 @@ "@scure/base": "npm:@scure/base@^1.1.6", "@sentry/deno": "https://deno.land/x/sentry@7.112.2/index.mjs", "@soapbox/kysely-pglite": "jsr:@soapbox/kysely-pglite@^1.0.0", - "@soapbox/logi": "jsr:@soapbox/logi@^0.2.1", + "@soapbox/logi": "jsr:@soapbox/logi@^0.3.0", "@soapbox/safe-fetch": "jsr:@soapbox/safe-fetch@^2.0.0", "@std/assert": "jsr:@std/assert@^0.225.1", "@std/cli": "jsr:@std/cli@^0.223.0", diff --git a/deno.lock b/deno.lock index 877a90de..6b28e2a4 100644 --- a/deno.lock +++ b/deno.lock @@ -49,7 +49,7 @@ "jsr:@nostrify/types@0.36": "0.36.0", "jsr:@nostrify/types@~0.30.1": "0.30.1", "jsr:@soapbox/kysely-pglite@1": "1.0.0", - "jsr:@soapbox/logi@~0.2.1": "0.2.1", + "jsr:@soapbox/logi@0.3": "0.3.0", "jsr:@soapbox/safe-fetch@2": "2.0.0", "jsr:@std/assert@0.223": "0.223.0", "jsr:@std/assert@0.224": "0.224.0", @@ -526,8 +526,8 @@ "npm:kysely@~0.27.4" ] }, - "@soapbox/logi@0.2.1": { - "integrity": "763d624c45adb74ec55e24911d14933d1883606c14701e171be7bfb76f9029be" + "@soapbox/logi@0.3.0": { + "integrity": "5aa5121e82422b0a1b5ec81790f75407c16c788d10af629cecef9a35d1b4c290" }, "@soapbox/safe-fetch@2.0.0": { "integrity": "f451d686501c76a0faa058fe9d2073676282a8a42c3b93c59159eb9191f11b5f", @@ -2353,7 +2353,7 @@ "jsr:@nostrify/policies@~0.36.1", "jsr:@nostrify/types@0.36", "jsr:@soapbox/kysely-pglite@1", - "jsr:@soapbox/logi@~0.2.1", + "jsr:@soapbox/logi@0.3", "jsr:@soapbox/safe-fetch@2", "jsr:@std/assert@~0.225.1", "jsr:@std/cli@0.223", diff --git a/src/db/KyselyLogger.ts b/src/db/KyselyLogger.ts index b640f5e5..45c10cc3 100644 --- a/src/db/KyselyLogger.ts +++ b/src/db/KyselyLogger.ts @@ -1,5 +1,4 @@ -import { logi } from '@soapbox/logi'; -import { JsonValue } from '@std/json'; +import { logi, LogiValue } from '@soapbox/logi'; import { Logger } from 'kysely'; import { dbQueriesCounter, dbQueryDurationHistogram } from '@/metrics.ts'; @@ -16,7 +15,7 @@ export const KyselyLogger: Logger = (event) => { dbQueryDurationHistogram.observe(duration); if (event.level === 'query') { - logi({ level: 'debug', ns: 'ditto.sql', sql, parameters: parameters as JsonValue, duration }); + logi({ level: 'debug', ns: 'ditto.sql', sql, parameters: parameters as LogiValue, duration }); } if (event.level === 'error') { @@ -24,7 +23,7 @@ export const KyselyLogger: Logger = (event) => { level: 'error', ns: 'ditto.sql', sql, - parameters: parameters as JsonValue, + parameters: parameters as LogiValue, error: errorJson(event.error), duration, }); diff --git a/src/startup.ts b/src/startup.ts index 7227cb8a..0cc2f26a 100644 --- a/src/startup.ts +++ b/src/startup.ts @@ -1,26 +1,9 @@ // Starts up applications required to run before the HTTP server is on. -import { logi } from '@soapbox/logi'; -import { encodeHex } from '@std/encoding/hex'; - import { Conf } from '@/config.ts'; import { cron } from '@/cron.ts'; import { startFirehose } from '@/firehose.ts'; import { startNotify } from '@/notify.ts'; -logi.handler = (log) => { - console.log(JSON.stringify(log, (_key, value) => { - if (typeof value === 'bigint') { - return value.toString(); - } - - if (value instanceof Uint8Array) { - return '\\x' + encodeHex(value); - } - - return value; - })); -}; - if (Conf.firehoseEnabled) { startFirehose(); } diff --git a/src/utils/log.ts b/src/utils/log.ts index 4d005a6f..28fcbf0d 100644 --- a/src/utils/log.ts +++ b/src/utils/log.ts @@ -1,10 +1,8 @@ -import { JsonValue } from '@std/json'; - /** Serialize an error into JSON for JSON logging. */ -export function errorJson(error: unknown): JsonValue { +export function errorJson(error: unknown): Error | null { if (error instanceof Error) { - return { name: error.name, msg: error.message, stack: error.stack }; + return error; + } else { + return null; } - - return { name: 'unknown', msg: String(error) }; }