mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor: ♻️ Replace logging system with @logtape/logtape
This commit is contained in:
parent
75992dfe62
commit
bc8220c8f9
28 changed files with 324 additions and 858 deletions
|
|
@ -1,10 +1,9 @@
|
|||
import { logger } from "@/loggers";
|
||||
import { response } from "@/response";
|
||||
import { getLogger } from "@logtape/logtape";
|
||||
import type { SocketAddress } from "bun";
|
||||
import { createMiddleware } from "hono/factory";
|
||||
import { matches } from "ip-matching";
|
||||
import { config } from "~/packages/config-manager";
|
||||
import { LogLevel } from "~/packages/log-manager";
|
||||
|
||||
const baitFile = async () => {
|
||||
const file = Bun.file(config.http.bait.send_file || "./beemovie.txt");
|
||||
|
|
@ -13,11 +12,9 @@ const baitFile = async () => {
|
|||
return file;
|
||||
}
|
||||
|
||||
await logger.log(
|
||||
LogLevel.Error,
|
||||
"Server.Bait",
|
||||
`Bait file not found: ${config.http.bait.send_file}`,
|
||||
);
|
||||
const logger = getLogger("server");
|
||||
|
||||
logger.error`Bait file not found: ${config.http.bait.send_file}`;
|
||||
};
|
||||
|
||||
export const bait = createMiddleware(async (context, next) => {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { logger } from "@/loggers";
|
||||
import { errorResponse } from "@/response";
|
||||
import { getLogger } from "@logtape/logtape";
|
||||
import type { SocketAddress } from "bun";
|
||||
import { createMiddleware } from "hono/factory";
|
||||
import { matches } from "ip-matching";
|
||||
import { config } from "~/packages/config-manager";
|
||||
import { LogLevel } from "~/packages/log-manager";
|
||||
|
||||
export const ipBans = createMiddleware(async (context, next) => {
|
||||
// Check for banned IPs
|
||||
|
|
@ -22,12 +21,10 @@ export const ipBans = createMiddleware(async (context, next) => {
|
|||
return errorResponse("Forbidden", 403);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.log(
|
||||
LogLevel.Error,
|
||||
"Server.IPCheck",
|
||||
`Error while parsing banned IP "${ip}" `,
|
||||
);
|
||||
logger.logError(LogLevel.Error, "Server.IPCheck", e as Error);
|
||||
const logger = getLogger("server");
|
||||
|
||||
logger.error`Error while parsing banned IP "${ip}" `;
|
||||
logger.error`${e}`;
|
||||
|
||||
return errorResponse(
|
||||
`A server error occured: ${(e as Error).message}`,
|
||||
|
|
|
|||
|
|
@ -1,17 +1,10 @@
|
|||
import { dualLogger } from "@/loggers";
|
||||
import type { SocketAddress } from "bun";
|
||||
import { debugRequest } from "@/api";
|
||||
import { createMiddleware } from "hono/factory";
|
||||
import { config } from "~/packages/config-manager";
|
||||
|
||||
export const logger = createMiddleware(async (context, next) => {
|
||||
const requestIp = context.env?.ip as SocketAddress | undefined | null;
|
||||
|
||||
if (config.logging.log_requests) {
|
||||
await dualLogger.logRequest(
|
||||
context.req.raw,
|
||||
config.logging.log_ip ? requestIp?.address : undefined,
|
||||
config.logging.log_requests_verbose,
|
||||
);
|
||||
await debugRequest(context.req.raw);
|
||||
}
|
||||
|
||||
await next();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue