Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !desktop
// +build !desktop

package cmd
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -50,7 +56,7 @@ func initLogger() {
}

stdlog.SetFlags(0)
stdlog.SetOutput(log.Logger)
stdlog.SetOutput(stdlogWriter)
}

// Execute runs command parsing chain
Expand Down
2 changes: 1 addition & 1 deletion internal/app/loophole/loophole.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
20 changes: 20 additions & 0 deletions internal/app/loophole/models/LevelWriter.go
Original file line number Diff line number Diff line change
@@ -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
}