From 24100c4cbee5a4115a9989d1234c1cdfd124df6d Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Thu, 4 May 2023 00:05:52 +0700 Subject: [PATCH] cmd/ctrld: use Windscribe fork of zerolog For supporting default log level notice. While at it, also fix a missing os.Exit call when setup router on non-supported platforms. --- cmd/ctrld/cli.go | 16 ++++++++-------- cmd/ctrld/cli_router_linux.go | 1 + cmd/ctrld/main.go | 4 ++-- go.mod | 6 +++++- go.sum | 10 +++++----- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/cmd/ctrld/cli.go b/cmd/ctrld/cli.go index 4f1af63..a5ca76f 100644 --- a/cmd/ctrld/cli.go +++ b/cmd/ctrld/cli.go @@ -335,7 +335,7 @@ func initCLI() { status = selfCheckStatus(status) switch status { case service.StatusRunning: - mainLog.Warn().Msg("Service started") + mainLog.Notice().Msg("Service started") default: mainLog.Error().Msg("Service did not start, please check system/service log for details error") if runtime.GOOS == "linux" { @@ -379,7 +379,7 @@ func initCLI() { initLogging() if doTasks([]task{{s.Stop, true}}) { prog.resetDNS() - mainLog.Warn().Msg("Service stopped") + mainLog.Notice().Msg("Service stopped") } }, } @@ -401,7 +401,7 @@ func initCLI() { } initLogging() if doTasks([]task{{s.Restart, true}}) { - mainLog.Warn().Msg("Service restarted") + mainLog.Notice().Msg("Service restarted") } }, } @@ -426,13 +426,13 @@ func initCLI() { } switch status { case service.StatusUnknown: - mainLog.Warn().Msg("Unknown status") + mainLog.Notice().Msg("Unknown status") os.Exit(2) case service.StatusRunning: - mainLog.Warn().Msg("Service is running") + mainLog.Notice().Msg("Service is running") os.Exit(0) case service.StatusStopped: - mainLog.Warn().Msg("Service is stopped") + mainLog.Notice().Msg("Service is stopped") os.Exit(1) } }, @@ -477,7 +477,7 @@ NOTE: Uninstalling will set DNS to values provided by DHCP.`, if err := router.Cleanup(); err != nil { mainLog.Warn().Err(err).Msg("could not cleanup router") } - mainLog.Warn().Msg("Service uninstalled") + mainLog.Notice().Msg("Service uninstalled") return } }, @@ -887,7 +887,7 @@ func selfCheckStatus(status service.Status) service.Status { } func unsupportedPlatformHelp(cmd *cobra.Command) { - cmd.PrintErrln("Unsupported or incorrectly chosen router platform. Please open an issue and provide all relevant information: https://github.com/Control-D-Inc/ctrld/issues/new") + mainLog.Error().Msg("Unsupported or incorrectly chosen router platform. Please open an issue and provide all relevant information: https://github.com/Control-D-Inc/ctrld/issues/new") } func userHomeDir() (string, error) { diff --git a/cmd/ctrld/cli_router_linux.go b/cmd/ctrld/cli_router_linux.go index 6352c91..3bd70f1 100644 --- a/cmd/ctrld/cli_router_linux.go +++ b/cmd/ctrld/cli_router_linux.go @@ -46,6 +46,7 @@ func initRouterCLI() { case router.DDWrt, router.Merlin, router.OpenWrt, router.Ubios: default: unsupportedPlatformHelp(cmd) + os.Exit(1) } exe, err := os.Executable() if err != nil { diff --git a/cmd/ctrld/main.go b/cmd/ctrld/main.go index f3ecfb3..4f4c206 100644 --- a/cmd/ctrld/main.go +++ b/cmd/ctrld/main.go @@ -70,7 +70,7 @@ func initConsoleLogging() { case verbose > 1: zerolog.SetGlobalLevel(zerolog.DebugLevel) default: - zerolog.SetGlobalLevel(zerolog.WarnLevel) + zerolog.SetGlobalLevel(zerolog.NoticeLevel) } } @@ -99,7 +99,7 @@ func initLogging() { // TODO: find a better way. ctrld.ProxyLog = mainLog - zerolog.SetGlobalLevel(zerolog.WarnLevel) + zerolog.SetGlobalLevel(zerolog.NoticeLevel) logLevel := cfg.Service.LogLevel switch { case verbose == 1: diff --git a/go.mod b/go.mod index 1d1788c..169dc34 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/Control-D-Inc/ctrld go 1.20 require ( - github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 + github.com/coreos/go-systemd/v22 v22.5.0 github.com/cuonglm/osinfo v0.0.0-20230329055532-c513f836da19 github.com/frankban/quicktest v1.14.3 github.com/fsnotify/fsnotify v1.6.0 @@ -77,3 +77,7 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/mr-karan/doggo => github.com/Windscribe/doggo v0.0.0-20220919152748-2c118fc391f8 + +replace github.com/rs/zerolog => github.com/Windscribe/zerolog v0.0.0-20230503170159-e6aa153233be diff --git a/go.sum b/go.sum index 6aedff1..3b884b7 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,8 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Windscribe/zerolog v0.0.0-20230503170159-e6aa153233be h1:qBKVRi7Mom5heOkyZ+NCIu9HZBiNCsRqrRe5t9pooik= +github.com/Windscribe/zerolog v0.0.0-20230503170159-e6aa153233be/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 h1:Kk6a4nehpJ3UuJRqlA3JxYxBZEqCeOmATOvrbT4p9RA= github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -50,8 +52,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= -github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 h1:rtAn27wIbmOGUs7RIbVgPEjb31ehTVniDwPGXyMxm5U= -github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cuonglm/osinfo v0.0.0-20230329055532-c513f836da19 h1:7P/f19Mr0oa3ug8BYt4JuRe/Zq3dF4Mrr4m8+Kw+Hcs= @@ -247,9 +249,7 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rogpeppe/go-internal v1.8.1-0.20211023094830-115ce09fd6b4 h1:Ha8xCaq6ln1a+R91Km45Oq6lPXj2Mla6CRJYcuV2h1w= github.com/rogpeppe/go-internal v1.8.1-0.20211023094830-115ce09fd6b4/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= -github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY= -github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=