mirror of
https://github.com/RussellChamp/advent-of-code-2021.git
synced 2026-10-27 21:52:32 +00:00
day 16 part 1
This commit is contained in:
1 parent
4737afa383
commit
0c277a8404
11 files changed
+463
-1
No files matched your search
+30
-1
@@ -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...)
|
||||
|
||||
Reference in new issue
Block a user