1
0
Fork 0
forked from goffee/core

Added Level type - A custom int type with constants DEBUG, INFO, WARNING, ERROR in increasing severity order.

Added `minLevel` field to Logger struct to track the minimum level threshold.
Added `SetLevel()` and `GetLevel()` methods for dynamically changing/reading the log level at runtime.
This commit is contained in:
Zeni Kim 2026-05-06 16:06:25 -05:00
parent 5e389115fc
commit 0da7ea8ab1
3 changed files with 331 additions and 24 deletions

View file

@ -293,7 +293,6 @@ func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Ha
for _, header := range ctx.Response.headers {
w.Header().Add(header.key, header.val)
}
logger.CloseLogsFile()
var ct string
if ctx.Response.overrideContentType != "" {
ct = ctx.Response.overrideContentType
@ -334,7 +333,7 @@ func (n notFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
res := "{\"message\": \"Not Found\"}"
loggr.Error("Not Found")
loggr.Error(debug.Stack())
//loggr.Error(debug.Stack())
w.Header().Add(CONTENT_TYPE, CONTENT_TYPE_JSON)
w.Write([]byte(res))
}
@ -344,7 +343,7 @@ func (n methodNotAllowed) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusMethodNotAllowed)
res := "{\"message\": \"Method not allowed\"}"
loggr.Error("Method not allowed")
loggr.Error(debug.Stack())
//loggr.Error(debug.Stack())
w.Header().Add(CONTENT_TYPE, CONTENT_TYPE_JSON)
w.Write([]byte(res))
}
@ -372,7 +371,7 @@ var panicHandler = func(w http.ResponseWriter, r *http.Request, e interface{}) {
shrtMsg := fmt.Sprintf("%v", e)
loggr.Error(shrtMsg)
fmt.Println(shrtMsg)
loggr.Error(string(debug.Stack()))
//loggr.Error(string(debug.Stack()))
var res string
if env.GetVarOtherwiseDefault("APP_ENV", "local") == PRODUCTION {
res = "{\"message\": \"internal error\"}"