Skip to content

Commit d5079d6

Browse files
Improved logging output.
1 parent 9a141ea commit d5079d6

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/middleware.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function middleware(request: NextRequest): NextResponse {
115115
const referer = request.headers.get('referer') || '-'
116116
const clientIP = getClientIP(request)
117117

118-
// Create response
118+
// Create response (middleware runs before routing, so final status is unknown here)
119119
const response = NextResponse.next()
120120

121121
// Only log if this request should be logged
@@ -126,17 +126,17 @@ export function middleware(request: NextRequest): NextResponse {
126126
// Log the request immediately (before processing)
127127
const timestamp = new Date().toISOString()
128128
const fullUrl = pathname + search
129-
const status = response.status
129+
// We can't know the final route status in middleware; avoid logging a misleading 200
130130
// Calculate duration in ms
131131
const duration = Date.now() - startTime
132132

133133
logger.info(
134134
`${colors.gray}[${timestamp}]${colors.reset} ` +
135135
`${getColoredMethod(method)} ` +
136-
`${getColoredStatus(status)} ` +
137136
`${getColoredDuration(duration)} ` +
138137
`${colors.cyan}${fullUrl}${colors.reset} ` +
139-
`${colors.gray}from ${clientIP}${colors.reset}`
138+
`${colors.gray}from ${clientIP}${colors.reset} ` +
139+
`${colors.dim}(pre-route)${colors.reset}`
140140
)
141141

142142
// Log additional details in development

0 commit comments

Comments
 (0)