Skip to content

Commit

Permalink
🚑 Fix h2 logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jun 13, 2024
1 parent 034419f commit b17fab5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/common/middlewares/logger.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ export class LoggerMiddleware implements NestMiddleware{
res.on("finish", () => {
const path = req.url;
try{
const httpOrHttps = req.connection.localPort.toString() === process.env.HTTPS_PORT ? "HTTPS" : "HTTP";
let httpOrHttps;
if(!req.connection.localPort)
httpOrHttps = "H2";
else
httpOrHttps = req.connection.localPort.toString() === process.env.HTTPS_PORT ? "HTTPS" : "HTTP";
const method = req.method;
if(method === "OPTIONS")
return;
const statusCode = res.statusCode;
const duration = Date.now() - startTime;
// const resSize = res.getHeader("Content-Length") || "N/A";
const nRes = res as any;
const resSize = nRes._contentLength || "0";
const resSize: any = res.getHeader("Content-Length") || "0";
// const nRes = res as any;
// const resSize = nRes._contentLength || "0";
const intResSize = parseInt(resSize);
LoggerMiddleware.logger.log(`${httpOrHttps} ${method} ${path} ${statusCode} ${duration}ms ${intResSize}`);
LoggerMiddleware.requestTimeLogger(path, method, duration);
Expand Down

0 comments on commit b17fab5

Please sign in to comment.