Assist_Design/LOGGING_USAGE.md
T. Narantuya 0bf872e249 Refactor code formatting and improve documentation clarity
- Adjusted YAML and JSON files for consistent formatting, including healthcheck commands and package exports.
- Enhanced readability in various TypeScript files by standardizing string quotes and improving line breaks.
- Updated documentation across multiple files to improve clarity and consistency, including address system and logging levels.
- Removed unnecessary package-lock.json from shared package directory to streamline dependencies.
2025-09-09 18:19:54 +09:00

1.7 KiB

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)

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

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

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