enhance: find out the highest log level of nginx

This commit is contained in:
0xJacky 2023-12-06 18:43:51 +08:00
parent b6cbc34e6f
commit 6fa90a15e4
No known key found for this signature in database
GPG key ID: B6E4A6E4A561BAF0
3 changed files with 9 additions and 6 deletions

View file

@ -21,11 +21,13 @@ var logLevel = [...]string{
"debug", "info", "notice", "warn", "error", "crit", "alert", "emerg",
}
func GetLogLevel(output string) int {
func GetLogLevel(output string) (level int) {
level = -1
for k, v := range logLevel {
if strings.Contains(output, v) {
return k
// Try to find the highest log level
level = k
}
}
return -1
return
}

View file

@ -9,7 +9,7 @@ import (
)
func execShell(cmd string) (out string) {
bytes, err := exec.Command("/bin/sh -c", cmd).CombinedOutput()
bytes, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
out = string(bytes)
if err != nil {
out += " " + err.Error()
@ -60,8 +60,6 @@ func Restart() (out string) {
out += execCommand("nginx")
logger.Debug(out)
return
}