diff --git a/cmd/root.go b/cmd/root.go index a99feff..095d700 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,3 +1,4 @@ +//go:build !desktop // +build !desktop package cmd @@ -9,6 +10,7 @@ import ( "time" "github.com/loophole/cli/config" + "github.com/loophole/cli/internal/app/loophole/models" "github.com/loophole/cli/internal/pkg/cache" "github.com/mattn/go-colorable" "github.com/rs/zerolog" @@ -33,6 +35,10 @@ func init() { } func initLogger() { + stdlogWriter := models.LevelWriter{ + Level: zerolog.InfoLevel, + MessagePrefix: "[sys]", + } logLocation := cache.GetLocalStorageFile(fmt.Sprintf("%s.log", time.Now().Format("2006-01-02--15-04-05")), "logs") f, err := os.Create(logLocation) @@ -50,7 +56,7 @@ func initLogger() { } stdlog.SetFlags(0) - stdlog.SetOutput(log.Logger) + stdlog.SetOutput(stdlogWriter) } // Execute runs command parsing chain diff --git a/internal/app/loophole/loophole.go b/internal/app/loophole/loophole.go index 332cb6a..7a4321c 100644 --- a/internal/app/loophole/loophole.go +++ b/internal/app/loophole/loophole.go @@ -358,7 +358,7 @@ func forward(remoteEndpointSpecs lm.RemoteEndpointSpecs, _, err := netClient.Get(urlmaker.GetSiteURL("https", remoteEndpointSpecs.SiteID, remoteEndpointSpecs.Domain)) if err != nil { - communication.TunnelError(remoteEndpointSpecs.TunnelID, "TLS Certificate failed to provision. Will be obtained with first request made by any client, therefore first execution may be slower") + communication.TunnelDebug(remoteEndpointSpecs.TunnelID, "TLS Certificate failed to provision. Will be obtained with first request made by any client, therefore first execution may be slower") } else { communication.TunnelInfo(remoteEndpointSpecs.TunnelID, "TLS Certificate successfully provisioned") } diff --git a/internal/app/loophole/models/LevelWriter.go b/internal/app/loophole/models/LevelWriter.go new file mode 100644 index 0000000..a28e99d --- /dev/null +++ b/internal/app/loophole/models/LevelWriter.go @@ -0,0 +1,20 @@ +package models + +import ( + "fmt" + + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" +) + +//Implementation of io.Writer which writes to zerolog with a configurable level +//and identifying prefix to prevent "???" level messages +type LevelWriter struct { + Level zerolog.Level + MessagePrefix string +} + +func (l LevelWriter) Write(p []byte) (n int, err error) { + log.WithLevel(l.Level).Msg(fmt.Sprintf("%s %s", l.MessagePrefix, string(p))) + return len(p), nil +}