Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

respect env NETDATA_LOG_SEVERITY_LEVEL #1351

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions cmd/godplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import (
)

var (
cd, _ = os.Getwd()
name = "go.d"
userDir = os.Getenv("NETDATA_USER_CONFIG_DIR")
stockDir = os.Getenv("NETDATA_STOCK_CONFIG_DIR")
varLibDir = os.Getenv("NETDATA_LIB_DIR")
lockDir = os.Getenv("NETDATA_LOCK_DIR")
watchPath = os.Getenv("NETDATA_PLUGINS_GOD_WATCH_PATH")
cd, _ = os.Getwd()
name = "go.d"
userDir = os.Getenv("NETDATA_USER_CONFIG_DIR")
stockDir = os.Getenv("NETDATA_STOCK_CONFIG_DIR")
varLibDir = os.Getenv("NETDATA_LIB_DIR")
lockDir = os.Getenv("NETDATA_LOCK_DIR")
watchPath = os.Getenv("NETDATA_PLUGINS_GOD_WATCH_PATH")
envLogSeverityLevel = os.Getenv("NETDATA_LOG_SEVERITY_LEVEL")

version = "unknown"
)
Expand Down Expand Up @@ -96,6 +97,10 @@ func main() {
return
}

if envLogSeverityLevel != "" {
logger.SetSeverityByName(envLogSeverityLevel)
}

if opts.Debug {
logger.SetSeverity(logger.DEBUG)
}
Expand Down
17 changes: 17 additions & 0 deletions logger/severity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

package logger

import "strings"

var globalSeverity = INFO

// Severity is a logging severity level
Expand Down Expand Up @@ -59,6 +61,21 @@ func SetSeverity(severity Severity) {
globalSeverity = severity
}

func SetSeverityByName(severity string) {
switch strings.ToUpper(severity) {
case "CRIT", "CRITICAL":
globalSeverity = CRITICAL
case "ERR", "ERROR":
globalSeverity = ERROR
case "WARN", "WARNING":
globalSeverity = WARNING
case "INFO":
globalSeverity = INFO
case "DEBUG":
globalSeverity = DEBUG
}
}

func IsDebug() bool {
return globalSeverity == DEBUG
}
Loading