import pino from "pino";
import { env } from "../../config/env.js";

/**
 * parent-bff 结构化日志（pino）。
 *
 * 字段对齐 02-architecture-design.md §6.3：
 * time, level, service, msg, traceId, parentId, childId, endpoint, duration, err
 *
 * 生产环境 JSON stdout，开发环境 pino-pretty 着色输出。
 */
export const logger = pino({
  level: env.LOG_LEVEL,
  base: {
    service: "parent-bff",
    version: "0.1.0",
  },
  transport:
    env.NODE_ENV === "development"
      ? {
          target: "pino-pretty",
          options: { colorize: true },
        }
      : undefined,
});

export type Logger = typeof logger;
