Documentation ¶
Index ¶
- Constants
- Variables
- func DisableConsoleColor()
- func ErrorLogger() app.HandlerFunc
- func ErrorLoggerT(typ errors.ErrorType) app.HandlerFunc
- func ForceConsoleColor()
- func Logger() app.HandlerFunc
- func LoggerWithConfig(conf LoggerConfig) app.HandlerFunc
- func LoggerWithFormatter(f LogFormatter) app.HandlerFunc
- func LoggerWithWriter(out io.Writer, notlogged ...string) app.HandlerFunc
- func RunWindowsServer()
- func Viper(path ...string) *viper.Viper
- func Zap() (logger *zap.Logger)
- type LogFormatter
- type LogFormatterParams
- type LoggerConfig
Constants ¶
const ErrorTypeAny errors.ErrorType = 1<<64 - 1
const ErrorTypePrivate errors.ErrorType = 1 << 0
Variables ¶
var DefaultWriter io.Writer = os.Stdout
Functions ¶
func DisableConsoleColor ¶
func DisableConsoleColor()
DisableConsoleColor disables color output in the console.
func ErrorLogger ¶
func ErrorLogger() app.HandlerFunc
ErrorLogger returns a HandlerFunc for any error type.
func ErrorLoggerT ¶
func ErrorLoggerT(typ errors.ErrorType) app.HandlerFunc
ErrorLoggerT returns a HandlerFunc for a given error type.
func ForceConsoleColor ¶
func ForceConsoleColor()
ForceConsoleColor force color output in the console.
func Logger ¶
func Logger() app.HandlerFunc
Logger instances a Logger middleware that will write the logs to gin.DefaultWriter. By default, gin.DefaultWriter = os.Stdout.
func LoggerWithConfig ¶
func LoggerWithConfig(conf LoggerConfig) app.HandlerFunc
LoggerWithConfig instance a Logger middleware with config.
func LoggerWithFormatter ¶
func LoggerWithFormatter(f LogFormatter) app.HandlerFunc
LoggerWithFormatter instance a Logger middleware with the specified log format function.
func LoggerWithWriter ¶
func LoggerWithWriter(out io.Writer, notlogged ...string) app.HandlerFunc
LoggerWithWriter instance a Logger middleware with the specified writer buffer. Example: os.Stdout, a file opened in write mode, a socket...
func RunWindowsServer ¶
func RunWindowsServer()
func Viper ¶
Viper // 优先级: 命令行 > 环境变量 > 默认值 Author [SliverHorn](https://github.com/SliverHorn)
func Zap ¶
Zap 获取 zap.Logger Author [SliverHorn](https://github.com/SliverHorn)
Types ¶
type LogFormatter ¶
type LogFormatter func(params LogFormatterParams) string
LogFormatter gives the signature of the formatter function passed to LoggerWithFormatter
type LogFormatterParams ¶
type LogFormatterParams struct { Request *protocol.Request // TimeStamp shows the time after the server returns a response. TimeStamp time.Time // StatusCode is HTTP response code. StatusCode int // Latency is how much time the server cost to process a certain request. Latency time.Duration // ClientIP equals Context's ClientIP method. ClientIP string // Method is the HTTP method given to the request. Method string // Path is a path the client requests. Path string // ErrorMessage is set if error has occurred in processing the request. ErrorMessage string // BodySize is the size of the Response Body BodySize int // Keys are the keys set on the request's context. Keys map[string]any // contains filtered or unexported fields }
LogFormatterParams is the structure any formatter will be handed when time to log comes
func (*LogFormatterParams) IsOutputColor ¶
func (p *LogFormatterParams) IsOutputColor() bool
IsOutputColor indicates whether can colors be outputted to the log.
func (*LogFormatterParams) MethodColor ¶
func (p *LogFormatterParams) MethodColor() string
MethodColor is the ANSI color for appropriately logging http method to a terminal.
func (*LogFormatterParams) ResetColor ¶
func (p *LogFormatterParams) ResetColor() string
ResetColor resets all escape attributes.
func (*LogFormatterParams) StatusCodeColor ¶
func (p *LogFormatterParams) StatusCodeColor() string
StatusCodeColor is the ANSI color for appropriately logging http status code to a terminal.
type LoggerConfig ¶
type LoggerConfig struct { // Optional. Default value is gin.defaultLogFormatter Formatter LogFormatter // Output is a writer where logs are written. // Optional. Default value is gin.DefaultWriter. Output io.Writer // SkipPaths is an url path array which logs are not written. // Optional. SkipPaths []string }
LoggerConfig defines the config for Logger middleware.