Documentation ¶
Index ¶
- func AccessLogger(logger *log.Logger) gin.HandlerFunc
- func Debug(msg string, fields ...zap.Field)
- func Error(msg string, fields ...zap.Field)
- func GinLogger() gin.HandlerFunc
- func Info(msg string, fields ...zap.Field)
- func NewLogger(cfg *LoggerConfig) (*log.Logger, error)
- func NewZapLogger(logFile, logLevel string, logToConsole bool, logToFile bool)
- type LogConfig
- type LoggerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AccessLogger ¶
func AccessLogger(logger *log.Logger) gin.HandlerFunc
AccessLogger 返回Gin中间件,用于记录访问日志
func NewLogger ¶
func NewLogger(cfg *LoggerConfig) (*log.Logger, error)
NewLogger 返回一个新的日志对象,可以根据配置输出到终端或日志文件
func NewZapLogger ¶
NewZapLogger 初始化
// 初始化日志 logPath := "./logs/app.log" // 输出到文件和控制台 logs.NewZapLogger(logPath, "debug",true, true) logs.Error("This is a test log message.") // 只输出到文件 logs.NewZapLogger(logPath, "debug",false, true) logs.Info("This is another test log message.") // 只输出到控制台 logs.NewZapLogger(logPath,"debug", true, false) logs.Info("This is a third test log message.")
Types ¶
Click to show internal directories.
Click to hide internal directories.