FILE / ScuroNeko/SNekLog

http.go

Исходный файл и его история в репозитории.
FILE dd3c7286d27688e6b17037e94d522b5ca6cce968
Files
SNekLog/http.go
T
ScuroNeko 812caed471
Golang lint / lint (push) Successful in 42s
(new): add log level helpers and HTTP method levels
- move LogLevel and predefined levels into levels.go
- add level-specific constructors for info/warn/error/fatal/debug
- add predefined HTTP method log levels and LogLevelForMethod
- unify Logger Print/Println internals and add Printf
- improve GoDoc coverage for exported APIs
2026-04-27 16:36:30 +03:00

48 lines
1.4 KiB
Go

package sneklog
import "net/http"
// HTTP method-specific log levels.
var (
HTTPGetLevel = NewInfoLogLevelWithColors("get", FgGreen, BgNone)
HTTPHeadLevel = NewInfoLogLevelWithColors("head", FgCyan, BgNone)
HTTPPostLevel = NewInfoLogLevelWithColors("post", FgBlue, BgNone)
HTTPPutLevel = NewInfoLogLevelWithColors("put", FgYellow, BgNone)
HTTPPatchLevel = NewInfoLogLevelWithColors("patch", FgMagenta, BgNone)
HTTPDeleteLevel = NewInfoLogLevelWithColors("delete", FgRed, BgNone)
)
// Additional HTTP method-specific log levels.
var (
HTTPOptionsLevel = NewDebugLogLevelWithColors("options", FgWhite, BgNone)
HTTPConnectLevel = NewDebugLogLevelWithColors("connect", FgCyan, BgNone)
HTTPTraceLevel = NewDebugLogLevelWithColors("trace", FgWhite, BgNone)
HTTPUnknownLevel = NewDebugLogLevelWithColors("http", FgWhite, BgNone)
)
// LogLevelForMethod returns the predefined log level associated with an HTTP method.
func LogLevelForMethod(method string) LogLevel {
switch method {
case http.MethodGet:
return HTTPGetLevel
case http.MethodHead:
return HTTPHeadLevel
case http.MethodPost:
return HTTPPostLevel
case http.MethodPut:
return HTTPPutLevel
case http.MethodPatch:
return HTTPPatchLevel
case http.MethodDelete:
return HTTPDeleteLevel
case http.MethodOptions:
return HTTPOptionsLevel
case http.MethodConnect:
return HTTPConnectLevel
case http.MethodTrace:
return HTTPTraceLevel
default:
return HTTPUnknownLevel
}
}