day 16 part 1

This commit is contained in:
RussellChamp committed 2021-12-16 15:54:05 -05:00
1 parent 4737afa383
commit 0c277a8404
11 files changed
+463 -1

No files matched your search

+30 -1
View File
@@ -1,12 +1,16 @@
package log
import "fmt"
import (
"fmt"
"strconv"
)
const (
NONE = 0
NORMAL = 1
DEBUG = 2
DIAGNOSTIC = 3
NEVER = 99
)
const (
@@ -24,6 +28,31 @@ func SetLogLevel(level int) {
}
}
func SetLogLevelFromArgs(argMap map[string]string) {
logLevelStr, found := argMap["log"]
if found {
logLevel, err := NORMAL, error(nil)
switch logLevelStr {
case "NONE", "None", "none":
logLevel = NONE
case "NORMAL", "Normal", "normal":
logLevel = NORMAL
case "DEBUG", "Debug", "debug":
logLevel = DEBUG
case "DIAG", "DIAGNOSTIC", "Diag", "Diagnostic", "diag", "diagnostic":
logLevel = DIAGNOSTIC
default:
logLevel, err = strconv.Atoi(logLevelStr)
}
if err != nil {
panic("Error when parsing log level")
}
SetLogLevel(logLevel)
}
}
func Print(minLevel int, a ...interface{}) (int, error) {
if LOG_LEVEL >= minLevel {
return fmt.Print(a...)