Assist_Design/LOGGING_USAGE.md

70 lines
1.7 KiB
Markdown
Raw Normal View History

# 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/domain";
// 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/domain"`
-**Production ready** with automatic security redaction