Upgrade Logi

This commit is contained in:
Alex Gleason 2025-01-30 01:43:57 -06:00
parent 8f4ae833ca
commit b473898cef
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
5 changed files with 12 additions and 32 deletions

View file

@ -52,7 +52,7 @@
"@scure/base": "npm:@scure/base@^1.1.6", "@scure/base": "npm:@scure/base@^1.1.6",
"@sentry/deno": "https://deno.land/x/sentry@7.112.2/index.mjs", "@sentry/deno": "https://deno.land/x/sentry@7.112.2/index.mjs",
"@soapbox/kysely-pglite": "jsr:@soapbox/kysely-pglite@^1.0.0", "@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", "@soapbox/safe-fetch": "jsr:@soapbox/safe-fetch@^2.0.0",
"@std/assert": "jsr:@std/assert@^0.225.1", "@std/assert": "jsr:@std/assert@^0.225.1",
"@std/cli": "jsr:@std/cli@^0.223.0", "@std/cli": "jsr:@std/cli@^0.223.0",

8
deno.lock generated
View file

@ -49,7 +49,7 @@
"jsr:@nostrify/types@0.36": "0.36.0", "jsr:@nostrify/types@0.36": "0.36.0",
"jsr:@nostrify/types@~0.30.1": "0.30.1", "jsr:@nostrify/types@~0.30.1": "0.30.1",
"jsr:@soapbox/kysely-pglite@1": "1.0.0", "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:@soapbox/safe-fetch@2": "2.0.0",
"jsr:@std/assert@0.223": "0.223.0", "jsr:@std/assert@0.223": "0.223.0",
"jsr:@std/assert@0.224": "0.224.0", "jsr:@std/assert@0.224": "0.224.0",
@ -526,8 +526,8 @@
"npm:kysely@~0.27.4" "npm:kysely@~0.27.4"
] ]
}, },
"@soapbox/logi@0.2.1": { "@soapbox/logi@0.3.0": {
"integrity": "763d624c45adb74ec55e24911d14933d1883606c14701e171be7bfb76f9029be" "integrity": "5aa5121e82422b0a1b5ec81790f75407c16c788d10af629cecef9a35d1b4c290"
}, },
"@soapbox/safe-fetch@2.0.0": { "@soapbox/safe-fetch@2.0.0": {
"integrity": "f451d686501c76a0faa058fe9d2073676282a8a42c3b93c59159eb9191f11b5f", "integrity": "f451d686501c76a0faa058fe9d2073676282a8a42c3b93c59159eb9191f11b5f",
@ -2353,7 +2353,7 @@
"jsr:@nostrify/policies@~0.36.1", "jsr:@nostrify/policies@~0.36.1",
"jsr:@nostrify/types@0.36", "jsr:@nostrify/types@0.36",
"jsr:@soapbox/kysely-pglite@1", "jsr:@soapbox/kysely-pglite@1",
"jsr:@soapbox/logi@~0.2.1", "jsr:@soapbox/logi@0.3",
"jsr:@soapbox/safe-fetch@2", "jsr:@soapbox/safe-fetch@2",
"jsr:@std/assert@~0.225.1", "jsr:@std/assert@~0.225.1",
"jsr:@std/cli@0.223", "jsr:@std/cli@0.223",

View file

@ -1,5 +1,4 @@
import { logi } from '@soapbox/logi'; import { logi, LogiValue } from '@soapbox/logi';
import { JsonValue } from '@std/json';
import { Logger } from 'kysely'; import { Logger } from 'kysely';
import { dbQueriesCounter, dbQueryDurationHistogram } from '@/metrics.ts'; import { dbQueriesCounter, dbQueryDurationHistogram } from '@/metrics.ts';
@ -16,7 +15,7 @@ export const KyselyLogger: Logger = (event) => {
dbQueryDurationHistogram.observe(duration); dbQueryDurationHistogram.observe(duration);
if (event.level === 'query') { 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') { if (event.level === 'error') {
@ -24,7 +23,7 @@ export const KyselyLogger: Logger = (event) => {
level: 'error', level: 'error',
ns: 'ditto.sql', ns: 'ditto.sql',
sql, sql,
parameters: parameters as JsonValue, parameters: parameters as LogiValue,
error: errorJson(event.error), error: errorJson(event.error),
duration, duration,
}); });

View file

@ -1,26 +1,9 @@
// Starts up applications required to run before the HTTP server is on. // 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 { Conf } from '@/config.ts';
import { cron } from '@/cron.ts'; import { cron } from '@/cron.ts';
import { startFirehose } from '@/firehose.ts'; import { startFirehose } from '@/firehose.ts';
import { startNotify } from '@/notify.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) { if (Conf.firehoseEnabled) {
startFirehose(); startFirehose();
} }

View file

@ -1,10 +1,8 @@
import { JsonValue } from '@std/json';
/** Serialize an error into JSON for JSON logging. */ /** 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) { 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) };
} }