- Updated nest-cli.json to enable output directory deletion and refined TypeScript compiler options. - Modified package.json to improve development command for BFF with preserved watch output. - Adjusted tsconfig.json to extend from a higher-level configuration and removed unnecessary options. - Enhanced logging.module.ts to simplify logger configuration and improve log message formatting. - Updated next.config.mjs to manage server-only libraries and optimize Webpack configuration. - Refined error logging in various components for better clarity and consistency.
67 lines
1.7 KiB
Markdown
67 lines
1.7 KiB
Markdown
# Simple Centralized Logging
|
|
|
|
## ✅ **Single Pino Logger Everywhere**
|
|
|
|
We now use **one simple Pino logger** across the entire application:
|
|
|
|
- **Frontend (Portal)**: Uses the same Pino logger
|
|
- **Backend (BFF)**: Uses `nestjs-pino` with the same configuration
|
|
- **Shared**: Single logger configuration
|
|
|
|
## 🚀 **Usage Examples**
|
|
|
|
### **Frontend (Portal)**
|
|
```typescript
|
|
import { logger, log } from "@/lib/logger";
|
|
|
|
// Simple logging
|
|
log.info("User logged in", { userId: "123" });
|
|
log.error("API call failed", error);
|
|
|
|
// Direct Pino usage
|
|
logger.info({ userId: "123" }, "User logged in");
|
|
```
|
|
|
|
### **Backend (BFF) - Dependency Injection**
|
|
```typescript
|
|
import { Logger } from "nestjs-pino";
|
|
|
|
@Injectable()
|
|
export class UserService {
|
|
constructor(@Inject(Logger) private readonly logger: Logger) {}
|
|
|
|
async findUser(id: string) {
|
|
this.logger.info({ userId: id }, "Finding user");
|
|
}
|
|
}
|
|
```
|
|
|
|
### **Backend (BFF) - Direct Import**
|
|
```typescript
|
|
import { logger, log } from "@customer-portal/shared";
|
|
|
|
// Simple logging
|
|
log.info("Service started");
|
|
log.error("Database error", error);
|
|
|
|
// Direct Pino usage
|
|
logger.info({ userId: "123" }, "User action");
|
|
```
|
|
|
|
## 🔧 **Configuration**
|
|
|
|
All configuration is in one place: `packages/shared/src/logger.ts`
|
|
|
|
- **Development**: Pretty printed logs with colors
|
|
- **Production**: JSON logs for log aggregation
|
|
- **Browser**: Console-friendly output
|
|
- **Security**: Automatic redaction of sensitive fields
|
|
|
|
## 🎯 **Benefits**
|
|
|
|
- ✅ **One logger** instead of multiple complex systems
|
|
- ✅ **Same configuration** everywhere
|
|
- ✅ **No more fs/promises errors**
|
|
- ✅ **Simple imports** - just `import { log } from "@customer-portal/shared"`
|
|
- ✅ **Production ready** with automatic security redaction
|