Documentation
¶
Index ¶
- Constants
- Variables
- func AccessLog(method, path string, statusCode, bytes int, clientIP string, ...)
- func Debug(format string, args ...interface{})
- func DefaultGinLogger() gin.HandlerFunc
- func Error(format string, args ...interface{})
- func Fatal(format string, args ...interface{})
- func FormatAccessLog(method, path string, statusCode, bytes int, clientIP string, ...) (string, string)
- func GinLogger(logger *Logger) gin.HandlerFunc
- func Info(format string, args ...interface{})
- func Warning(format string, args ...interface{})
- type LogConfig
- type Logger
- func (l *Logger) AccessLog(method, path string, statusCode, bytes int, clientIP string, ...)
- func (l *Logger) Debug(format string, args ...interface{})
- func (l *Logger) Error(format string, args ...interface{})
- func (l *Logger) Fatal(format string, args ...interface{})
- func (l *Logger) GetLevel() int
- func (l *Logger) Info(format string, args ...interface{})
- func (l *Logger) SetLevel(level int)
- func (l *Logger) SetOutput(w io.Writer)
- func (l *Logger) Warning(format string, args ...interface{})
Constants ¶
View Source
const ( DEBUG = iota INFO WARNING ERROR FATAL )
日志级别常量
View Source
const ( // MaxLogSize 单个日志文件的最大大小(MB) MaxLogSize = 128 // MaxLogBackups 保留的旧日志文件的最大数量 MaxLogBackups = 3 // MaxLogAge 保留的旧日志文件的最大天数 MaxLogAge = 28 )
日志配置常量
Variables ¶
View Source
var ( MethodColor = color.New(color.FgGreen, color.Bold).SprintfFunc() PathColor = color.CyanString StatusColor = map[int]func(format string, a ...interface{}) string{ 200: color.New(color.FgGreen).SprintfFunc(), 201: color.New(color.FgGreen).SprintfFunc(), 301: color.New(color.FgYellow).SprintfFunc(), 302: color.New(color.FgYellow).SprintfFunc(), 400: color.New(color.FgMagenta).SprintfFunc(), 401: color.New(color.FgMagenta).SprintfFunc(), 403: color.New(color.FgMagenta).SprintfFunc(), 404: color.New(color.FgMagenta).SprintfFunc(), 500: color.New(color.FgRed, color.Bold).SprintfFunc(), 501: color.New(color.FgRed, color.Bold).SprintfFunc(), 502: color.New(color.FgRed, color.Bold).SprintfFunc(), 503: color.New(color.FgRed, color.Bold).SprintfFunc(), } TimeColor = color.New(color.FgWhite).SprintfFunc() ClientIPColor = color.New(color.FgWhite).SprintfFunc() BytesColor = color.New(color.FgMagenta).SprintfFunc() )
访问日志的颜色
Functions ¶
func FormatAccessLog ¶
func FormatAccessLog(method, path string, statusCode, bytes int, clientIP string, duration time.Duration) (string, string)
FormatAccessLog 格式化HTTP访问日志
func GinLogger ¶
func GinLogger(logger *Logger) gin.HandlerFunc
GinLogger 返回一个Gin中间件,用于记录HTTP请求的访问日志
Types ¶
type LogConfig ¶
type LogConfig struct {
// 日志级别
Level int
// 是否启用文件日志
EnableFileLog bool
// 日志文件名(不包含路径)
Filename string
}
LogConfig 日志配置
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger 结构表示一个日志记录器
var Default *Logger
默认日志实例
func (*Logger) AccessLog ¶
func (l *Logger) AccessLog(method, path string, statusCode, bytes int, clientIP string, duration time.Duration)
AccessLog 记录HTTP访问日志
Click to show internal directories.
Click to hide internal directories.