diff --git a/cmd/twister/config.toml b/cmd/twister/config.toml index 881bbe6..2f89486 100644 --- a/cmd/twister/config.toml +++ b/cmd/twister/config.toml @@ -1,2 +1,5 @@ [server] address = "127.0.0.1:8000" + +[log] +level = "Debug" diff --git a/cmd/twister/main.go b/cmd/twister/main.go index 436815a..15a357c 100644 --- a/cmd/twister/main.go +++ b/cmd/twister/main.go @@ -3,19 +3,33 @@ package main import ( _ "embed" "fmt" + "os" "git.supernets.org/vortex/twister/internal/config" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" ) var ( //go:embed config.toml content []byte - version = "0.2.0" + version = "0.2.1" ) func main() { conf := config.Parse(content) conf.Version = version + + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + + level, err := zerolog.ParseLevel(conf.Log.Level) + if err != nil { + log.Err(err).Msg("") + os.Exit(1) + } + + zerolog.SetGlobalLevel(level) + fmt.Println(conf) } diff --git a/go.mod b/go.mod index 8173456..00eb3c8 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,13 @@ module git.supernets.org/vortex/twister go 1.23.0 -require github.com/BurntSushi/toml v1.4.0 +require ( + github.com/BurntSushi/toml v1.4.0 + github.com/rs/zerolog v1.33.0 +) + +require ( + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect + golang.org/x/sys v0.12.0 // indirect +) diff --git a/go.sum b/go.sum index 8bc10f6..3b8bdcf 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,17 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/internal/config/config.go b/internal/config/config.go index af4db26..04e401f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -4,9 +4,15 @@ package config type Config struct { Version string *Server `toml:"server"` + *Log `toml:"log"` } // Server config type Server struct { Address string } + +// Log config +type Log struct { + Level string +} diff --git a/internal/config/parse.go b/internal/config/parse.go index 41ae8b6..64bbc35 100644 --- a/internal/config/parse.go +++ b/internal/config/parse.go @@ -1,6 +1,11 @@ package config -import "github.com/BurntSushi/toml" +import ( + "os" + + "github.com/BurntSushi/toml" + "github.com/rs/zerolog/log" +) // Parse the config func Parse(content []byte) *Config { @@ -8,7 +13,8 @@ func Parse(content []byte) *Config { err := toml.Unmarshal(content, &cfg) if err != nil { - panic(err) + log.Err(err).Msg("") + os.Exit(1) } return cfg