mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-06-06 00:37:24 +03:00
Add log levels (#332)
This commit is contained in:
parent
d1cf0ca7eb
commit
3d59c7d0de
5 changed files with 56 additions and 17 deletions
|
@ -118,10 +118,28 @@ func New(tmplBox *rice.Box, extraData map[string]string, secret []byte) *echo.Ec
|
|||
templates["wake_on_lan_hosts.html"] = template.Must(template.New("wake_on_lan_hosts").Funcs(funcs).Parse(tmplBaseString + tmplWakeOnLanHostsString))
|
||||
templates["about.html"] = template.Must(template.New("about").Funcs(funcs).Parse(tmplBaseString + aboutPageString))
|
||||
|
||||
e.Logger.SetLevel(log.DEBUG)
|
||||
lvl, err := util.ParseLogLevel(util.LookupEnvOrString(util.LogLevel, "INFO"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
logConfig := middleware.DefaultLoggerConfig
|
||||
logConfig.Skipper = func(c echo.Context) bool {
|
||||
resp := c.Response()
|
||||
if resp.Status >= 500 && lvl > log.ERROR { // do not log if response is 5XX but log level is higher than ERROR
|
||||
return true
|
||||
} else if resp.Status >= 400 && lvl > log.WARN { // do not log if response is 4XX but log level is higher than WARN
|
||||
return true
|
||||
} else if lvl > log.DEBUG { // do not log if log level is higher than DEBUG
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
e.Logger.SetLevel(lvl)
|
||||
e.Pre(middleware.RemoveTrailingSlash())
|
||||
e.Use(middleware.Logger())
|
||||
e.Use(middleware.LoggerWithConfig(logConfig))
|
||||
e.HideBanner = true
|
||||
e.HidePort = lvl > log.INFO // hide the port output if the log level is higher than INFO
|
||||
e.Validator = NewValidator()
|
||||
e.Renderer = &TemplateRegistry{
|
||||
templates: templates,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue