Skip to content

Commit 2f733fa

Browse files
Added additional details to logger output.
1 parent 0b67fbc commit 2f733fa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/middleware.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function getColoredDuration(ms: number): string {
6666
* Get client IP address from various headers
6767
*/
6868
function getClientIP(request: NextRequest): string {
69-
// Check various headers that might contain the real IP
69+
// In Docker with nginx as reverse proxy, ensure nginx sets X-Forwarded-For and X-Real-IP headers
7070
const xForwardedFor = request.headers.get('x-forwarded-for')
7171
const xRealIP = request.headers.get('x-real-ip')
7272
const cfConnectingIP = request.headers.get('cf-connecting-ip')
@@ -123,10 +123,14 @@ export function middleware(request: NextRequest): NextResponse {
123123
// Log the request immediately (before processing)
124124
const timestamp = new Date().toISOString()
125125
const fullUrl = pathname + search
126+
const status = response.status
127+
const duration = Date.now() - startTime
126128

127129
logger.info(
128130
`${colors.gray}[${timestamp}]${colors.reset} ` +
129131
`${getColoredMethod(method)} ` +
132+
`${getColoredStatus(status)} ` +
133+
`${getColoredDuration(duration)} ` +
130134
`${colors.cyan}${fullUrl}${colors.reset} ` +
131135
`${colors.gray}from ${clientIP}${colors.reset}`
132136
)

0 commit comments

Comments
 (0)