Skip to content

Commit

Permalink
added request logger
Browse files Browse the repository at this point in the history
  • Loading branch information
cdleveille committed Jun 8, 2024
1 parent 88779f6 commit c735a36
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/middleware/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Elysia } from "elysia";

import { useCors, useErrorHandler, useHelmet, useSwagger } from "@middleware";
import { useCors, useErrorHandler, useHelmet, useLogger, useSwagger } from "@middleware";

export const initMiddleware = (app: Elysia) => {
useCors(app);
useErrorHandler(app);
useLogger(app);
useCors(app);
useHelmet(app);
useSwagger(app);
};

export * from "./cors";
export * from "./errorHandler";
export * from "./helmet";
export * from "./logger";
export * from "./swagger";
12 changes: 12 additions & 0 deletions src/middleware/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Elysia } from "elysia";

import { Config } from "@helpers";
import { log } from "@services";

export const useLogger = (app: Elysia) => {
app.onResponse(({ request, error, path }) => {
const { message } = error as { message?: string };
if (message) return;
!Config.IS_PROD && log.info(`${new Date().toISOString()} ${request.method} ${path} 200`);
});
};

0 comments on commit c735a36

Please sign in to comment.