- 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
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user