Skip to content

Commit

Permalink
log level
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Jun 26, 2024
1 parent c5e3c91 commit 18d3a72
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/service/common/middle/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const NextEntry = ({ beforeCallback = [] }: { beforeCallback?: Promise<an
return async function api(req: ApiRequestProps, res: NextApiResponse) {
const start = Date.now();
addLog.debug(`Request start ${req.url}`);

try {
await Promise.all([withNextCors(req, res), ...beforeCallback]);

Expand All @@ -22,10 +23,15 @@ export const NextEntry = ({ beforeCallback = [] }: { beforeCallback?: Promise<an
response = await handler(req, res);
}

const contentType = res.getHeader('Content-Type');

addLog.debug(`Request finish ${req.url}, time: ${Date.now() - start}ms`);
// Get request duration
const duration = Date.now() - start;
if (duration < 2000) {
addLog.debug(`Request finish ${req.url}, time: ${duration}ms`);
} else {
addLog.warn(`Request finish ${req.url}, time: ${duration}ms`);
}

const contentType = res.getHeader('Content-Type');
if ((!contentType || contentType === 'application/json') && !res.writableFinished) {
return jsonRes(res, {
code: 200,
Expand Down

0 comments on commit 18d3a72

Please sign in to comment.