package logger

import "gopkg.in/lumberjack.v2"

// newRotateWriter 根据配置创建 lumberjack.Logger 作为日志轮转写入器
// 日志文件位于 cfg.Path 目录下，文件名格式为 nex-YYYY-MM-DD.log
func newRotateWriter(cfg Config) *lumberjack.Logger {
	maxSize := cfg.MaxSize
	if maxSize <= 0 {
		maxSize = 100
	}

	maxBackups := cfg.MaxBackups
	if maxBackups <= 0 {
		maxBackups = 10
	}

	maxAge := cfg.MaxAge
	if maxAge <= 0 {
		maxAge = 30
	}

	return &lumberjack.Logger{
		Filename:   logFilePath(cfg.Path),
		MaxSize:    maxSize, // MB
		MaxBackups: maxBackups,
		MaxAge:     maxAge, // days
		Compress:   cfg.Compress,
	}
}
