Update throttler configuration and enhance logging setup
- Adjusted authentication rate limit TTL from 15 minutes to 10 minutes for stricter control. - Improved logging configuration to reduce noise by ignoring specific HTTP requests and customizing serializers. - Refactored logging in checkout components to utilize useCallback for better performance and removed unnecessary console logs.
This commit is contained in:
parent
48116bf160
commit
0f7d680782
@ -14,7 +14,7 @@ export const createThrottlerConfig = (configService: ConfigService): ThrottlerMo
|
|||||||
// Stricter rate limiting for authentication endpoints
|
// Stricter rate limiting for authentication endpoints
|
||||||
{
|
{
|
||||||
name: "auth",
|
name: "auth",
|
||||||
ttl: configService.get<number>("AUTH_RATE_LIMIT_TTL", 900000), // 15 minutes
|
ttl: configService.get<number>("AUTH_RATE_LIMIT_TTL", 600000), // 10 minutes
|
||||||
limit: configService.get<number>("AUTH_RATE_LIMIT_LIMIT", 3), // 3 attempts
|
limit: configService.get<number>("AUTH_RATE_LIMIT_LIMIT", 3), // 3 attempts
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@ -8,6 +8,35 @@ import { LoggerModule } from "nestjs-pino";
|
|||||||
pinoHttp: {
|
pinoHttp: {
|
||||||
level: process.env.LOG_LEVEL || "info",
|
level: process.env.LOG_LEVEL || "info",
|
||||||
name: process.env.APP_NAME || "customer-portal-bff",
|
name: process.env.APP_NAME || "customer-portal-bff",
|
||||||
|
|
||||||
|
// Reduce HTTP request/response noise
|
||||||
|
autoLogging: {
|
||||||
|
ignore: (req) => {
|
||||||
|
// Skip logging for health checks and static assets
|
||||||
|
const url = req.url || '';
|
||||||
|
return url.includes('/health') ||
|
||||||
|
url.includes('/favicon') ||
|
||||||
|
url.includes('/_next/') ||
|
||||||
|
url.includes('/api/auth/session'); // Skip frequent session checks
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Custom serializers to reduce response body logging
|
||||||
|
serializers: {
|
||||||
|
req: (req) => ({
|
||||||
|
method: req.method,
|
||||||
|
url: req.url,
|
||||||
|
// Don't log headers or body in production
|
||||||
|
...(process.env.NODE_ENV === 'development' && {
|
||||||
|
headers: req.headers
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
res: (res) => ({
|
||||||
|
statusCode: res.statusCode,
|
||||||
|
// Don't log response body to reduce noise
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
transport:
|
transport:
|
||||||
process.env.NODE_ENV === "development"
|
process.env.NODE_ENV === "development"
|
||||||
? {
|
? {
|
||||||
@ -15,7 +44,8 @@ import { LoggerModule } from "nestjs-pino";
|
|||||||
options: {
|
options: {
|
||||||
colorize: true,
|
colorize: true,
|
||||||
translateTime: "yyyy-mm-dd HH:MM:ss",
|
translateTime: "yyyy-mm-dd HH:MM:ss",
|
||||||
ignore: "pid,hostname",
|
ignore: "pid,hostname,req,res", // Hide request/response details in pretty output
|
||||||
|
messageFormat: "{msg}",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
@ -23,6 +53,8 @@ import { LoggerModule } from "nestjs-pino";
|
|||||||
paths: [
|
paths: [
|
||||||
"req.headers.authorization",
|
"req.headers.authorization",
|
||||||
"req.headers.cookie",
|
"req.headers.cookie",
|
||||||
|
"req.body", // Redact request bodies
|
||||||
|
"res.body", // Redact response bodies
|
||||||
"password",
|
"password",
|
||||||
"token",
|
"token",
|
||||||
"secret",
|
"secret",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect, useMemo, Suspense } from "react";
|
import { useState, useEffect, useMemo, useCallback, Suspense } from "react";
|
||||||
import { useSearchParams, useRouter } from "next/navigation";
|
import { useSearchParams, useRouter } from "next/navigation";
|
||||||
import { PageLayout } from "@/components/layout/page-layout";
|
import { PageLayout } from "@/components/layout/page-layout";
|
||||||
import { ShieldCheckIcon, ExclamationTriangleIcon } from "@heroicons/react/24/outline";
|
import { ShieldCheckIcon, ExclamationTriangleIcon } from "@heroicons/react/24/outline";
|
||||||
@ -245,23 +245,15 @@ function CheckoutContent() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddressConfirmed = (address?: Address) => {
|
const handleAddressConfirmed = useCallback((address?: Address) => {
|
||||||
console.log("🎯 PARENT: handleAddressConfirmed called with:", address);
|
|
||||||
console.log("🎯 PARENT: Current addressConfirmed state before:", addressConfirmed);
|
|
||||||
setAddressConfirmed(true);
|
setAddressConfirmed(true);
|
||||||
setConfirmedAddress(address || null);
|
setConfirmedAddress(address || null);
|
||||||
console.log("🎯 PARENT: addressConfirmed state set to true");
|
}, []);
|
||||||
|
|
||||||
// Force a log after state update (in next tick)
|
const handleAddressIncomplete = useCallback(() => {
|
||||||
setTimeout(() => {
|
|
||||||
console.log("🎯 PARENT: addressConfirmed state after update:", addressConfirmed);
|
|
||||||
}, 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleAddressIncomplete = () => {
|
|
||||||
setAddressConfirmed(false);
|
setAddressConfirmed(false);
|
||||||
setConfirmedAddress(null);
|
setConfirmedAddress(null);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
if (checkoutState.loading) {
|
if (checkoutState.loading) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -128,19 +128,9 @@ export function AddressConfirmation({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleConfirmAddress = () => {
|
const handleConfirmAddress = () => {
|
||||||
console.log("🏠 CONFIRM ADDRESS CLICKED", {
|
|
||||||
billingInfo,
|
|
||||||
hasAddress: !!billingInfo?.address,
|
|
||||||
address: billingInfo?.address,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (billingInfo?.address) {
|
if (billingInfo?.address) {
|
||||||
console.log("🏠 Calling onAddressConfirmed with:", billingInfo.address);
|
|
||||||
onAddressConfirmed(billingInfo.address);
|
onAddressConfirmed(billingInfo.address);
|
||||||
setAddressConfirmed(true);
|
setAddressConfirmed(true);
|
||||||
console.log("🏠 Address confirmed state set to true");
|
|
||||||
} else {
|
|
||||||
console.log("🏠 No billing info or address available");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
96
docs/LOGGING_LEVELS.md
Normal file
96
docs/LOGGING_LEVELS.md
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
# 📊 Logging Configuration Guide
|
||||||
|
|
||||||
|
## Quick Log Level Changes
|
||||||
|
|
||||||
|
### Using the Script (Recommended)
|
||||||
|
```bash
|
||||||
|
# Check current level
|
||||||
|
./scripts/set-log-level.sh
|
||||||
|
|
||||||
|
# Set to minimal logging (production-like)
|
||||||
|
./scripts/set-log-level.sh warn
|
||||||
|
|
||||||
|
# Set to normal development logging
|
||||||
|
./scripts/set-log-level.sh info
|
||||||
|
|
||||||
|
# Set to detailed debugging
|
||||||
|
./scripts/set-log-level.sh debug
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manual Configuration
|
||||||
|
Edit `.env` file:
|
||||||
|
```bash
|
||||||
|
LOG_LEVEL="info" # Change this value
|
||||||
|
```
|
||||||
|
|
||||||
|
## Log Levels Explained
|
||||||
|
|
||||||
|
| Level | Numeric | What You'll See | Best For |
|
||||||
|
|-------|---------|-----------------|----------|
|
||||||
|
| `error` | 0 | Only critical errors | Production monitoring |
|
||||||
|
| `warn` | 1 | Warnings + errors | Quiet development |
|
||||||
|
| `info` | 2 | General operations | **Normal development** ⭐ |
|
||||||
|
| `debug` | 3 | Detailed debugging | Troubleshooting issues |
|
||||||
|
| `trace` | 4 | Very verbose tracing | Deep debugging |
|
||||||
|
|
||||||
|
## What's Been Optimized
|
||||||
|
|
||||||
|
### ✅ Reduced Noise
|
||||||
|
- **HTTP requests/responses**: Filtered out health checks, static assets
|
||||||
|
- **Request bodies**: Hidden by default (security + noise reduction)
|
||||||
|
- **Response bodies**: Hidden by default (reduces overwhelming output)
|
||||||
|
- **Session checks**: Frequent `/api/auth/session` calls ignored
|
||||||
|
|
||||||
|
### ✅ Cleaner Output
|
||||||
|
- **Pretty formatting**: Colored, timestamped logs in development
|
||||||
|
- **Message focus**: Emphasizes actual log messages over metadata
|
||||||
|
- **Structured data**: Still available but not overwhelming
|
||||||
|
|
||||||
|
### ✅ Security Enhanced
|
||||||
|
- **Sensitive data**: Automatically redacted (tokens, passwords, etc.)
|
||||||
|
- **Production ready**: No debug info exposed to customers
|
||||||
|
|
||||||
|
## Common Scenarios
|
||||||
|
|
||||||
|
### 🔇 Too Much Noise?
|
||||||
|
```bash
|
||||||
|
./scripts/set-log-level.sh warn
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🐛 Debugging Issues?
|
||||||
|
```bash
|
||||||
|
./scripts/set-log-level.sh debug
|
||||||
|
```
|
||||||
|
|
||||||
|
### 🚀 Normal Development?
|
||||||
|
```bash
|
||||||
|
./scripts/set-log-level.sh info
|
||||||
|
```
|
||||||
|
|
||||||
|
### 📊 Production Monitoring?
|
||||||
|
```bash
|
||||||
|
./scripts/set-log-level.sh error
|
||||||
|
```
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Core logging
|
||||||
|
LOG_LEVEL="info" # Main log level
|
||||||
|
DISABLE_HTTP_LOGGING="false" # Set to "true" to disable HTTP logs entirely
|
||||||
|
|
||||||
|
# Application context
|
||||||
|
APP_NAME="customer-portal-bff" # Service name in logs
|
||||||
|
NODE_ENV="development" # Affects log formatting
|
||||||
|
```
|
||||||
|
|
||||||
|
## Restart Required
|
||||||
|
|
||||||
|
After changing log levels, restart your development server:
|
||||||
|
```bash
|
||||||
|
# Stop current server (Ctrl+C)
|
||||||
|
# Then restart
|
||||||
|
pnpm dev
|
||||||
|
```
|
||||||
|
|
||||||
|
The new log level will take effect immediately.
|
||||||
@ -25,21 +25,26 @@ export const logger = pino({
|
|||||||
colorize: true,
|
colorize: true,
|
||||||
translateTime: "yyyy-mm-dd HH:MM:ss",
|
translateTime: "yyyy-mm-dd HH:MM:ss",
|
||||||
ignore: "pid,hostname",
|
ignore: "pid,hostname",
|
||||||
|
messageFormat: "{msg}", // Cleaner message format
|
||||||
|
hideObject: false, // Show structured data but cleaner
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Security: redact sensitive fields
|
// Security: redact sensitive fields and reduce noise
|
||||||
redact: {
|
redact: {
|
||||||
paths: [
|
paths: [
|
||||||
"req.headers.authorization",
|
"req.headers.authorization",
|
||||||
"req.headers.cookie",
|
"req.headers.cookie",
|
||||||
|
"req.body", // Hide request bodies
|
||||||
|
"res.body", // Hide response bodies
|
||||||
"password",
|
"password",
|
||||||
"token",
|
"token",
|
||||||
"secret",
|
"secret",
|
||||||
"jwt",
|
"jwt",
|
||||||
"apiKey",
|
"apiKey",
|
||||||
|
"data", // Hide large data objects
|
||||||
],
|
],
|
||||||
remove: true,
|
remove: true,
|
||||||
},
|
},
|
||||||
|
|||||||
43
scripts/set-log-level.sh
Executable file
43
scripts/set-log-level.sh
Executable file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script to easily change log levels
|
||||||
|
# Usage: ./scripts/set-log-level.sh [error|warn|info|debug|trace]
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
echo "Current LOG_LEVEL: $(grep LOG_LEVEL .env | cut -d'=' -f2 | tr -d '"')"
|
||||||
|
echo ""
|
||||||
|
echo "Usage: $0 [error|warn|info|debug|trace]"
|
||||||
|
echo ""
|
||||||
|
echo "Log Levels:"
|
||||||
|
echo " error - Only errors (least verbose)"
|
||||||
|
echo " warn - Warnings and errors"
|
||||||
|
echo " info - General information (recommended)"
|
||||||
|
echo " debug - Detailed debugging info"
|
||||||
|
echo " trace - Very detailed tracing (most verbose)"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
LEVEL=$1
|
||||||
|
|
||||||
|
# Validate log level
|
||||||
|
case $LEVEL in
|
||||||
|
error|warn|info|debug|trace)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid log level: $LEVEL"
|
||||||
|
echo "Valid levels: error, warn, info, debug, trace"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Update .env file
|
||||||
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# macOS
|
||||||
|
sed -i '' "s/LOG_LEVEL=\".*\"/LOG_LEVEL=\"$LEVEL\"/" .env
|
||||||
|
else
|
||||||
|
# Linux
|
||||||
|
sed -i "s/LOG_LEVEL=\".*\"/LOG_LEVEL=\"$LEVEL\"/" .env
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ Log level changed to: $LEVEL"
|
||||||
|
echo "🔄 Restart your development server to apply changes"
|
||||||
Loading…
x
Reference in New Issue
Block a user