fix(federation): 🐛 Fix debug logger not correctly outputting

This commit is contained in:
Jesse Wierzbinski 2024-05-21 15:23:48 -10:00
parent eab61b38f1
commit fd38161769
No known key found for this signature in database
3 changed files with 15 additions and 3 deletions

View file

@ -1,3 +1,4 @@
import { debugRequest } from "@api";
import { import {
type EntityValidator, type EntityValidator,
SignatureConstructor, SignatureConstructor,
@ -42,5 +43,12 @@ export const objectToInboxRequest = async (
body: JSON.stringify(object), body: JSON.stringify(object),
}); });
return await ctor.sign(request); const signed = await ctor.sign(request);
if (config.debug.federation) {
// Debug request
await debugRequest(signed);
}
return signed;
}; };

View file

@ -24,7 +24,7 @@ import { fromZodError } from "zod-validation-error";
import type { Application } from "~database/entities/Application"; import type { Application } from "~database/entities/Application";
import { getFromHeader } from "~database/entities/User"; import { getFromHeader } from "~database/entities/User";
import type { User } from "~packages/database-interface/user"; import type { User } from "~packages/database-interface/user";
import { LogLevel } from "~packages/log-manager"; import { LogLevel, LogManager } from "~packages/log-manager";
import type { APIRouteMetadata, HttpVerb } from "~types/api"; import type { APIRouteMetadata, HttpVerb } from "~types/api";
export const applyConfig = (routeMeta: APIRouteMetadata) => { export const applyConfig = (routeMeta: APIRouteMetadata) => {
@ -302,7 +302,10 @@ export const jsonOrForm = () => {
}); });
}; };
export const debugRequest = async (req: Request, logger = consoleLogger) => { export const debugRequest = async (
req: Request,
logger = new LogManager(Bun.stdout),
) => {
const body = await req.clone().text(); const body = await req.clone().text();
await logger.log( await logger.log(
LogLevel.DEBUG, LogLevel.DEBUG,

View file

@ -10,6 +10,7 @@ const isEntry = true;
export const logger = new LogManager( export const logger = new LogManager(
isEntry ? requests_log : Bun.file("/dev/null"), isEntry ? requests_log : Bun.file("/dev/null"),
); );
export const consoleLogger = new LogManager( export const consoleLogger = new LogManager(
isEntry ? Bun.stdout : Bun.file("/dev/null"), isEntry ? Bun.stdout : Bun.file("/dev/null"),
!noColors, !noColors,