mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Upgrade Logi
This commit is contained in:
parent
8f4ae833ca
commit
b473898cef
5 changed files with 12 additions and 32 deletions
|
|
@ -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",
|
||||
|
|
|
|||
8
deno.lock
generated
8
deno.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue