maptile/log/log.go

21 lines
534 B
Go
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package log
import (
"log/slog"
"gopkg.in/natefinch/lumberjack.v2"
)
func init() {
logFile := &lumberjack.Logger{
Filename: "logs/app.log", // 日志文件路径
MaxSize: 10, // 单个日志文件的最大大小MB
MaxBackups: 5, // 保留的旧日志文件最大数量
MaxAge: 30, // 保留旧日志文件的最大天数
Compress: true, // 是否压缩旧日志文件
}
logger := slog.New(slog.NewJSONHandler(logFile, nil))
slog.SetDefault(logger)
}