// Package logger ...
//
// Description : logger ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2025-10-30 16:54
package logger

import (
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
)

var (
	Instance *zap.Logger
)

// 日志实例初始化默认输出到标准输出
func init() {
	cfg := zap.NewProductionConfig()
	cfg.OutputPaths = []string{"stdout"}
	cfg.ErrorOutputPaths = []string{"stderr"}
	cfg.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
	logger, err := cfg.Build()
	if err != nil {
		panic("init logger error: " + err.Error())
	}
	Instance = logger.Sugar().Desugar()
}

// Disable 禁用日志
func Disable() {
	Instance = zap.NewNop()
}

// SetInstance 设置日志实例
func SetInstance(l *zap.Logger) {
	if nil == l {
		return
	}
	Instance = l
}

const (
	RecordType = "GIN_LOG"
)

const (
	CodeInjectCommonParam       = "inject-common-param"
	CodeLogicHook               = "logic-hook"
	CodeParamValidateFailure    = "param-validate-failure"
	CodeLogicErrorWrapper       = "logic-error-wrapper"
	CodeLogicSseInitError       = "sse-init-error"
	CodeLogicSseClosedError     = "sse-closed-error"
	CodeServicePanic            = "service-panic"              // 服务发生 panic
	CodeServiceRateLimitFailure = "service-rate-limit-failure" // 服务流控出现异常
	CodeServiceRateLimitDisable = "service-rate-limit-disable" // 服务流控校验未通过
)
