Browse Source

:art: Use pterm for logging

Ettore Di Giacinto 3 years ago
parent
commit
03f1a779b8
18 changed files with 282 additions and 111 deletions
  1. 2 3
      cmd/api.go
  2. 4 5
      cmd/file.go
  3. 2 3
      cmd/join.go
  4. 18 7
      cmd/main.go
  5. 4 5
      cmd/service.go
  6. 20 5
      cmd/util.go
  7. 4 0
      go.mod
  8. 30 0
      go.sum
  9. 10 11
      main.go
  10. 14 15
      pkg/discovery/dht.go
  11. 4 4
      pkg/discovery/mdns.go
  12. 3 3
      pkg/edgevpn/config.go
  13. 4 4
      pkg/edgevpn/connection.go
  14. 18 13
      pkg/edgevpn/edgevpn.go
  15. 6 6
      pkg/edgevpn/files.go
  16. 12 14
      pkg/edgevpn/options.go
  17. 13 13
      pkg/edgevpn/services.go
  18. 114 0
      pkg/logger/logger.go

+ 2 - 3
cmd/api.go

@@ -5,10 +5,9 @@ import (
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/urfave/cli"
 	"github.com/urfave/cli"
-	"go.uber.org/zap"
 )
 )
 
 
-func API(l *zap.Logger) cli.Command {
+func API() cli.Command {
 	return cli.Command{
 	return cli.Command{
 		Name:        "api",
 		Name:        "api",
 		Description: "api starts an http server to display network informations",
 		Description: "api starts an http server to display network informations",
@@ -19,7 +18,7 @@ func API(l *zap.Logger) cli.Command {
 			},
 			},
 		),
 		),
 		Action: func(c *cli.Context) error {
 		Action: func(c *cli.Context) error {
-			e := edgevpn.New(cliToOpts(l, c)...)
+			e := edgevpn.New(cliToOpts(c)...)
 
 
 			mw, err := e.MessageWriter()
 			mw, err := e.MessageWriter()
 			if err != nil {
 			if err != nil {

+ 4 - 5
cmd/file.go

@@ -4,10 +4,9 @@ import (
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/urfave/cli"
 	"github.com/urfave/cli"
-	"go.uber.org/zap"
 )
 )
 
 
-func FileSend(l *zap.Logger) cli.Command {
+func FileSend() cli.Command {
 	return cli.Command{
 	return cli.Command{
 		Name:        "file-send",
 		Name:        "file-send",
 		Description: "send a file to the network",
 		Description: "send a file to the network",
@@ -16,7 +15,7 @@ func FileSend(l *zap.Logger) cli.Command {
 			cli.StringFlag{Name: "path"},
 			cli.StringFlag{Name: "path"},
 		),
 		),
 		Action: func(c *cli.Context) error {
 		Action: func(c *cli.Context) error {
-			e := edgevpn.New(cliToOpts(l, c)...)
+			e := edgevpn.New(cliToOpts(c)...)
 
 
 			mw, err := e.MessageWriter()
 			mw, err := e.MessageWriter()
 			if err != nil {
 			if err != nil {
@@ -38,7 +37,7 @@ func FileSend(l *zap.Logger) cli.Command {
 	}
 	}
 }
 }
 
 
-func FileReceive(l *zap.Logger) cli.Command {
+func FileReceive() cli.Command {
 	return cli.Command{
 	return cli.Command{
 		Name:        "file-receive",
 		Name:        "file-receive",
 		Description: "receive a file locally",
 		Description: "receive a file locally",
@@ -47,7 +46,7 @@ func FileReceive(l *zap.Logger) cli.Command {
 			cli.StringFlag{Name: "path"},
 			cli.StringFlag{Name: "path"},
 		),
 		),
 		Action: func(c *cli.Context) error {
 		Action: func(c *cli.Context) error {
-			e := edgevpn.New(cliToOpts(l, c)...)
+			e := edgevpn.New(cliToOpts(c)...)
 
 
 			mw, err := e.MessageWriter()
 			mw, err := e.MessageWriter()
 			if err != nil {
 			if err != nil {

+ 2 - 3
cmd/join.go

@@ -4,16 +4,15 @@ import (
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/urfave/cli"
 	"github.com/urfave/cli"
-	"go.uber.org/zap"
 )
 )
 
 
-func Join(l *zap.Logger) cli.Command {
+func Join() cli.Command {
 	return cli.Command{
 	return cli.Command{
 		Name:        "join",
 		Name:        "join",
 		Description: "join the network without activating any interface",
 		Description: "join the network without activating any interface",
 		Flags:       CommonFlags,
 		Flags:       CommonFlags,
 		Action: func(c *cli.Context) error {
 		Action: func(c *cli.Context) error {
-			e := edgevpn.New(cliToOpts(l, c)...)
+			e := edgevpn.New(cliToOpts(c)...)
 
 
 			mw, err := e.MessageWriter()
 			mw, err := e.MessageWriter()
 			if err != nil {
 			if err != nil {

+ 18 - 7
cmd/main.go

@@ -7,7 +7,6 @@ import (
 	"github.com/mudler/edgevpn/internal"
 	"github.com/mudler/edgevpn/internal"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/urfave/cli"
 	"github.com/urfave/cli"
-	"go.uber.org/zap"
 	"gopkg.in/yaml.v2"
 	"gopkg.in/yaml.v2"
 )
 )
 
 
@@ -22,6 +21,18 @@ var CommonFlags []cli.Flag = []cli.Flag{
 		Usage:  "Specify a path to a edgevpn config file",
 		Usage:  "Specify a path to a edgevpn config file",
 		EnvVar: "EDGEVPNCONFIG",
 		EnvVar: "EDGEVPNCONFIG",
 	},
 	},
+	&cli.StringFlag{
+		Name:   "log-level",
+		Usage:  "Specify loglevel",
+		EnvVar: "EDGEVPNLOGLEVEL",
+		Value:  "info",
+	},
+	&cli.StringFlag{
+		Name:   "libp2p-log-level",
+		Usage:  "Specify libp2p loglevel",
+		EnvVar: "EDGEVPNLIBP2PLOGLEVEL",
+		Value:  "fatal",
+	},
 	&cli.StringFlag{
 	&cli.StringFlag{
 		Name:   "token",
 		Name:   "token",
 		Usage:  "Specify an edgevpn token in place of a config file",
 		Usage:  "Specify an edgevpn token in place of a config file",
@@ -48,7 +59,7 @@ func MainFlags() []cli.Flag {
 		}}, CommonFlags...)
 		}}, CommonFlags...)
 }
 }
 
 
-func Main(l *zap.Logger) func(c *cli.Context) error {
+func Main() func(c *cli.Context) error {
 	return func(c *cli.Context) error {
 	return func(c *cli.Context) error {
 		if c.Bool("g") {
 		if c.Bool("g") {
 			// Generates a new config and exit
 			// Generates a new config and exit
@@ -68,16 +79,16 @@ func Main(l *zap.Logger) func(c *cli.Context) error {
 			os.Exit(0)
 			os.Exit(0)
 		}
 		}
 
 
-		e := edgevpn.New(cliToOpts(l, c)...)
+		e := edgevpn.New(cliToOpts(c)...)
 
 
-		l.Sugar().Info(Copyright)
+		e.Logger().Info(Copyright)
 
 
-		l.Sugar().Infof("Version: %s commit: %s", internal.Version, internal.Commit)
+		e.Logger().Infof("Version: %s commit: %s", internal.Version, internal.Commit)
 
 
-		l.Sugar().Info("Start")
+		e.Logger().Info("Start")
 
 
 		if err := e.Start(); err != nil {
 		if err := e.Start(); err != nil {
-			l.Sugar().Fatal(err.Error())
+			e.Logger().Fatal(err.Error())
 		}
 		}
 
 
 		return nil
 		return nil

+ 4 - 5
cmd/service.go

@@ -4,10 +4,9 @@ import (
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/blockchain"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/urfave/cli"
 	"github.com/urfave/cli"
-	"go.uber.org/zap"
 )
 )
 
 
-func ServiceAdd(l *zap.Logger) cli.Command {
+func ServiceAdd() cli.Command {
 	return cli.Command{
 	return cli.Command{
 		Name:        "service-add",
 		Name:        "service-add",
 		Description: "expose a service to the network",
 		Description: "expose a service to the network",
@@ -16,7 +15,7 @@ func ServiceAdd(l *zap.Logger) cli.Command {
 			cli.StringFlag{Name: "remoteaddress"},
 			cli.StringFlag{Name: "remoteaddress"},
 		),
 		),
 		Action: func(c *cli.Context) error {
 		Action: func(c *cli.Context) error {
-			e := edgevpn.New(cliToOpts(l, c)...)
+			e := edgevpn.New(cliToOpts(c)...)
 
 
 			mw, err := e.MessageWriter()
 			mw, err := e.MessageWriter()
 			if err != nil {
 			if err != nil {
@@ -38,7 +37,7 @@ func ServiceAdd(l *zap.Logger) cli.Command {
 	}
 	}
 }
 }
 
 
-func ServiceConnect(l *zap.Logger) cli.Command {
+func ServiceConnect() cli.Command {
 	return cli.Command{
 	return cli.Command{
 		Name:        "service-connect",
 		Name:        "service-connect",
 		Description: "bind a local port to connect to a remote service",
 		Description: "bind a local port to connect to a remote service",
@@ -48,7 +47,7 @@ func ServiceConnect(l *zap.Logger) cli.Command {
 			cli.StringFlag{Name: "srcaddress"},
 			cli.StringFlag{Name: "srcaddress"},
 		),
 		),
 		Action: func(c *cli.Context) error {
 		Action: func(c *cli.Context) error {
-			e := edgevpn.New(cliToOpts(l, c)...)
+			e := edgevpn.New(cliToOpts(c)...)
 
 
 			mw, err := e.MessageWriter()
 			mw, err := e.MessageWriter()
 			if err != nil {
 			if err != nil {

+ 20 - 5
cmd/util.go

@@ -3,23 +3,38 @@ package cmd
 import (
 import (
 	"github.com/ipfs/go-log"
 	"github.com/ipfs/go-log"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
 	"github.com/mudler/edgevpn/pkg/edgevpn"
+	"github.com/mudler/edgevpn/pkg/logger"
 	"github.com/songgao/water"
 	"github.com/songgao/water"
 	"github.com/urfave/cli"
 	"github.com/urfave/cli"
-	"go.uber.org/zap"
 )
 )
 
 
-func cliToOpts(l *zap.Logger, c *cli.Context) []edgevpn.Option {
+func cliToOpts(c *cli.Context) []edgevpn.Option {
 	config := c.String("config")
 	config := c.String("config")
 	address := c.String("address")
 	address := c.String("address")
 	iface := c.String("interface")
 	iface := c.String("interface")
+	logLevel := c.String("log-level")
+	libp2plogLevel := c.String("libp2p-log-level")
+
+	lvl, err := log.LevelFromString(logLevel)
+	if err != nil {
+		lvl = log.LevelError
+	}
+
+	llger := logger.New(lvl)
+
+	libp2plvl, err := log.LevelFromString(libp2plogLevel)
+	if err != nil {
+		libp2plvl = log.LevelFatal
+	}
+
 	token := c.String("token")
 	token := c.String("token")
 	if config == "" &&
 	if config == "" &&
 		token == "" {
 		token == "" {
-		l.Sugar().Fatal("EDGEVPNCONFIG or EDGEVPNTOKEN not supplied. At least a config file is required")
+		llger.Fatal("EDGEVPNCONFIG or EDGEVPNTOKEN not supplied. At least a config file is required")
 	}
 	}
 	return []edgevpn.Option{
 	return []edgevpn.Option{
-		edgevpn.Logger(l),
-		edgevpn.LogLevel(log.LevelInfo),
+		edgevpn.Logger(llger),
+		edgevpn.LibP2PLogLevel(libp2plvl),
 		edgevpn.MaxMessageSize(2 << 20), // 2MB
 		edgevpn.MaxMessageSize(2 << 20), // 2MB
 		edgevpn.WithInterfaceMTU(1450),
 		edgevpn.WithInterfaceMTU(1450),
 		edgevpn.WithPacketMTU(1420),
 		edgevpn.WithPacketMTU(1420),

+ 4 - 0
go.mod

@@ -3,6 +3,7 @@ module github.com/mudler/edgevpn
 go 1.16
 go 1.16
 
 
 require (
 require (
+	github.com/gookit/color v1.5.0 // indirect
 	github.com/ipfs/go-ipns v0.1.2 // indirect
 	github.com/ipfs/go-ipns v0.1.2 // indirect
 	github.com/ipfs/go-log v1.0.5 // indirect
 	github.com/ipfs/go-log v1.0.5 // indirect
 	github.com/ipfs/go-log/v2 v2.3.0
 	github.com/ipfs/go-log/v2 v2.3.0
@@ -15,8 +16,10 @@ require (
 	github.com/libp2p/go-libp2p-pubsub v0.5.4
 	github.com/libp2p/go-libp2p-pubsub v0.5.4
 	github.com/libp2p/go-libp2p-quic-transport v0.12.0 // indirect
 	github.com/libp2p/go-libp2p-quic-transport v0.12.0 // indirect
 	github.com/lthibault/jitterbug v2.0.0+incompatible
 	github.com/lthibault/jitterbug v2.0.0+incompatible
+	github.com/mudler/go-isterminal v0.0.0-20211031135732-5e4e06fc5a58 // indirect
 	github.com/multiformats/go-multiaddr v0.4.0
 	github.com/multiformats/go-multiaddr v0.4.0
 	github.com/pkg/errors v0.9.1
 	github.com/pkg/errors v0.9.1
+	github.com/pterm/pterm v0.12.33 // indirect
 	github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091
 	github.com/songgao/packets v0.0.0-20160404182456-549a10cd4091
 	github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
 	github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
 	github.com/urfave/cli v1.22.5 // indirect
 	github.com/urfave/cli v1.22.5 // indirect
@@ -25,6 +28,7 @@ require (
 	go.opencensus.io v0.23.0 // indirect
 	go.opencensus.io v0.23.0 // indirect
 	go.uber.org/zap v1.19.0
 	go.uber.org/zap v1.19.0
 	golang.org/x/net v0.0.0-20210913180222-943fd674d43e
 	golang.org/x/net v0.0.0-20210913180222-943fd674d43e
+	golang.org/x/sys v0.0.0-20211031064116-611d5d643895 // indirect
 	gopkg.in/yaml.v2 v2.4.0
 	gopkg.in/yaml.v2 v2.4.0
 )
 )
 
 

+ 30 - 0
go.sum

@@ -45,6 +45,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
 github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
 github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
 github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y=
+github.com/MarvinJWendt/testza v0.1.0/go.mod h1:7AxNvlfeHP7Z/hDQ5JtE3OKYT3XFUeLCDE2DQninSqs=
+github.com/MarvinJWendt/testza v0.2.1/go.mod h1:God7bhG8n6uQxwdScay+gjm9/LnO4D3kkcZX4hv9Rp8=
+github.com/MarvinJWendt/testza v0.2.8/go.mod h1:nwIcjmr0Zz+Rcwfh3/4UhBp7ePKVhuBExvZqnKYWlII=
+github.com/MarvinJWendt/testza v0.2.10/go.mod h1:pd+VWsoGUiFtq+hRKSU1Bktnn+DMCSrDrXDpX2bG66k=
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
 github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
 github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
 github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
 github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
@@ -65,6 +69,8 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5
 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
 github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
 github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
 github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
 github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
 github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
+github.com/atomicgo/cursor v0.0.1 h1:xdogsqa6YYlLfM+GyClC/Lchf7aiMerFiZQn7soTOoU=
+github.com/atomicgo/cursor v0.0.1/go.mod h1:cBON2QmmrysudxNBFthvMtN32r3jxVRIvzkUiF/RuIk=
 github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
 github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
 github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
 github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
 github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
 github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
@@ -273,6 +279,9 @@ github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk
 github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg=
 github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
+github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
+github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw=
+github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
 github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
 github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
@@ -711,6 +720,8 @@ github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
 github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
 github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
 github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
 github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
+github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
+github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
 github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
 github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
 github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
 github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
@@ -755,6 +766,8 @@ github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjW
 github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
 github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
 github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
 github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
 github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
 github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
+github.com/mudler/go-isterminal v0.0.0-20211031135732-5e4e06fc5a58 h1:bMXak5giXxc++J/TUY7qW24D8ASxqLQRqOoduuFgdIM=
+github.com/mudler/go-isterminal v0.0.0-20211031135732-5e4e06fc5a58/go.mod h1:bZC4k76DbPOxOcMq6Z9oEKAZrOhsfh9jAZ9Hu3qVAQI=
 github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
 github.com/multiformats/go-base32 v0.0.3 h1:tw5+NhuwaOjJCC5Pp82QuXbrmLzWg7uxlMFp8Nq/kkI=
 github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
 github.com/multiformats/go-base32 v0.0.3/go.mod h1:pLiuGC8y0QR3Ue4Zug5UzK9LjgbkL8NSQj0zQ5Nz/AA=
 github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
 github.com/multiformats/go-base36 v0.1.0 h1:JR6TyF7JjGd3m6FbLU2cOxhC0Li8z8dLNGQ89tUg4F4=
@@ -913,7 +926,15 @@ github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
 github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
 github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
 github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
 github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
 github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
+github.com/pterm/pterm v0.12.27/go.mod h1:PhQ89w4i95rhgE+xedAoqous6K9X+r6aSOI2eFF7DZI=
+github.com/pterm/pterm v0.12.29/go.mod h1:WI3qxgvoQFFGKGjGnJR849gU0TsEOvKn5Q8LlY1U7lg=
+github.com/pterm/pterm v0.12.30/go.mod h1:MOqLIyMOgmTDz9yorcYbcw+HsgoZo3BQfg2wtl3HEFE=
+github.com/pterm/pterm v0.12.31/go.mod h1:32ZAWZVXD7ZfG0s8qqHXePte42kdz8ECtRyEejaWgXU=
+github.com/pterm/pterm v0.12.33 h1:XiT50Pvdqn5O8FAiIqZMpXP6NkVEcmlUa+mkA1yWVCg=
+github.com/pterm/pterm v0.12.33/go.mod h1:x+h2uL+n7CP/rel9+bImHD5lF3nM9vJj80k9ybiiTTE=
 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
+github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
+github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
@@ -1027,6 +1048,8 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7V
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
 github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
 github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119 h1:YyPWX3jLOtYKulBR6AScGIs74lLrJcgeKRwcbAuQOG4=
 github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119 h1:YyPWX3jLOtYKulBR6AScGIs74lLrJcgeKRwcbAuQOG4=
 github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119/go.mod h1:/nuTSlK+okRfR/vnIPqR89fFKonnWPiZymN5ydRJkX8=
 github.com/xlzd/gotp v0.0.0-20181030022105-c8557ba2c119/go.mod h1:/nuTSlK+okRfR/vnIPqR89fFKonnWPiZymN5ydRJkX8=
+github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
+github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
 github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
 github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
 github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
 github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -1293,8 +1316,15 @@ golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 h1:uCLL3g5wH2xjxVREVuAbP9JM5
 golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 h1:xrCZDmdtoloIiooiA9q0OQb9r8HejIHYoHGhGCe1pGg=
 golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 h1:xrCZDmdtoloIiooiA9q0OQb9r8HejIHYoHGhGCe1pGg=
 golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211031064116-611d5d643895 h1:iaNpwpnrgL5jzWS0vCNnfa8HqzxveCFpFx3uC/X4Tps=
+golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

+ 10 - 11
main.go

@@ -16,18 +16,16 @@
 package main
 package main
 
 
 import (
 import (
+	"fmt"
 	"os"
 	"os"
 
 
 	"github.com/urfave/cli"
 	"github.com/urfave/cli"
 
 
 	"github.com/mudler/edgevpn/cmd"
 	"github.com/mudler/edgevpn/cmd"
 	internal "github.com/mudler/edgevpn/internal"
 	internal "github.com/mudler/edgevpn/internal"
-	"go.uber.org/zap"
 )
 )
 
 
 func main() {
 func main() {
-	l, _ := zap.NewProduction()
-	defer l.Sync() // flushes buffer, if any
 
 
 	app := &cli.App{
 	app := &cli.App{
 		Name:        "edgevpn",
 		Name:        "edgevpn",
@@ -38,19 +36,20 @@ func main() {
 		Copyright:   cmd.Copyright,
 		Copyright:   cmd.Copyright,
 		Flags:       cmd.MainFlags(),
 		Flags:       cmd.MainFlags(),
 		Commands: []cli.Command{
 		Commands: []cli.Command{
-			cmd.Join(l),
-			cmd.API(l),
-			cmd.ServiceAdd(l),
-			cmd.ServiceConnect(l),
-			cmd.FileReceive(l),
-			cmd.FileSend(l),
+			cmd.Join(),
+			cmd.API(),
+			cmd.ServiceAdd(),
+			cmd.ServiceConnect(),
+			cmd.FileReceive(),
+			cmd.FileSend(),
 		},
 		},
 
 
-		Action: cmd.Main(l),
+		Action: cmd.Main(),
 	}
 	}
 
 
 	err := app.Run(os.Args)
 	err := app.Run(os.Args)
 	if err != nil {
 	if err != nil {
-		l.Sugar().Fatal(err)
+		fmt.Println(err)
+		os.Exit(1)
 	}
 	}
 }
 }

+ 14 - 15
pkg/discovery/dht.go

@@ -5,8 +5,7 @@ import (
 	"sync"
 	"sync"
 	"time"
 	"time"
 
 
-	"go.uber.org/zap"
-
+	"github.com/ipfs/go-log"
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/network"
 	"github.com/libp2p/go-libp2p-core/network"
@@ -25,7 +24,7 @@ type DHT struct {
 	RendezvousString     string
 	RendezvousString     string
 	BootstrapPeers       AddrList
 	BootstrapPeers       AddrList
 	latestRendezvous     string
 	latestRendezvous     string
-	console              *zap.Logger
+	console              log.StandardLogger
 	RefreshDiscoveryTime int64
 	RefreshDiscoveryTime int64
 	dht                  *dht.IpfsDHT
 	dht                  *dht.IpfsDHT
 }
 }
@@ -64,7 +63,7 @@ func (d *DHT) startDHT(ctx context.Context, h host.Host) (*dht.IpfsDHT, error) {
 	return d.dht, nil
 	return d.dht, nil
 }
 }
 
 
-func (d *DHT) Run(c *zap.Logger, ctx context.Context, host host.Host) error {
+func (d *DHT) Run(c log.StandardLogger, ctx context.Context, host host.Host) error {
 	if d.KeyLength == 0 {
 	if d.KeyLength == 0 {
 		d.KeyLength = 12
 		d.KeyLength = 12
 	}
 	}
@@ -84,7 +83,7 @@ func (d *DHT) Run(c *zap.Logger, ctx context.Context, host host.Host) error {
 
 
 	// Bootstrap the DHT. In the default configuration, this spawns a Background
 	// Bootstrap the DHT. In the default configuration, this spawns a Background
 	// thread that will refresh the peer table every five minutes.
 	// thread that will refresh the peer table every five minutes.
-	c.Sugar().Info("Bootstrapping the DHT")
+	c.Info("Bootstrapping the DHT")
 	if err = kademliaDHT.Bootstrap(ctx); err != nil {
 	if err = kademliaDHT.Bootstrap(ctx); err != nil {
 		return err
 		return err
 	}
 	}
@@ -121,7 +120,7 @@ func (d *DHT) Run(c *zap.Logger, ctx context.Context, host host.Host) error {
 	return nil
 	return nil
 }
 }
 
 
-func (d *DHT) bootstrapPeers(c *zap.Logger, ctx context.Context, host host.Host) {
+func (d *DHT) bootstrapPeers(c log.StandardLogger, ctx context.Context, host host.Host) {
 	// Let's connect to the bootstrap nodes first. They will tell us about the
 	// Let's connect to the bootstrap nodes first. They will tell us about the
 	// other nodes in the network.
 	// other nodes in the network.
 	var wg sync.WaitGroup
 	var wg sync.WaitGroup
@@ -131,9 +130,9 @@ func (d *DHT) bootstrapPeers(c *zap.Logger, ctx context.Context, host host.Host)
 		go func() {
 		go func() {
 			defer wg.Done()
 			defer wg.Done()
 			if err := host.Connect(ctx, *peerinfo); err != nil {
 			if err := host.Connect(ctx, *peerinfo); err != nil {
-				c.Sugar().Warn(err.Error())
+				c.Debug(err.Error())
 			} else {
 			} else {
-				c.Sugar().Info("Connection established with bootstrap node:", *peerinfo)
+				c.Debug("Connection established with bootstrap node:", *peerinfo)
 			}
 			}
 		}()
 		}()
 	}
 	}
@@ -141,13 +140,13 @@ func (d *DHT) bootstrapPeers(c *zap.Logger, ctx context.Context, host host.Host)
 }
 }
 
 
 func (d *DHT) announceAndConnect(ctx context.Context, kademliaDHT *dht.IpfsDHT, host host.Host, rv string) error {
 func (d *DHT) announceAndConnect(ctx context.Context, kademliaDHT *dht.IpfsDHT, host host.Host, rv string) error {
-	d.console.Sugar().Info("Announcing ourselves...")
+	d.console.Debug("Announcing ourselves...")
 	routingDiscovery := discovery.NewRoutingDiscovery(kademliaDHT)
 	routingDiscovery := discovery.NewRoutingDiscovery(kademliaDHT)
 	discovery.Advertise(ctx, routingDiscovery, rv)
 	discovery.Advertise(ctx, routingDiscovery, rv)
-	d.console.Sugar().Info("Successfully announced!")
+	d.console.Debug("Successfully announced!")
 	// Now, look for others who have announced
 	// Now, look for others who have announced
 	// This is like your friend telling you the location to meet you.
 	// This is like your friend telling you the location to meet you.
-	d.console.Sugar().Info("Searching for other peers...")
+	d.console.Debug("Searching for other peers...")
 	peerChan, err := routingDiscovery.FindPeers(ctx, rv)
 	peerChan, err := routingDiscovery.FindPeers(ctx, rv)
 	if err != nil {
 	if err != nil {
 		return err
 		return err
@@ -164,14 +163,14 @@ func (d *DHT) announceAndConnect(ctx context.Context, kademliaDHT *dht.IpfsDHT,
 		//	defer wg.Done()
 		//	defer wg.Done()
 
 
 		if host.Network().Connectedness(p.ID) != network.Connected {
 		if host.Network().Connectedness(p.ID) != network.Connected {
-			d.console.Sugar().Info("Found peer:", p)
+			d.console.Debug("Found peer:", p)
 			if err := host.Connect(ctx, p); err != nil {
 			if err := host.Connect(ctx, p); err != nil {
-				d.console.Sugar().Info("Failed connecting to", p)
+				d.console.Debug("Failed connecting to", p)
 			} else {
 			} else {
-				d.console.Sugar().Info("Connected to:", p)
+				d.console.Debug("Connected to:", p)
 			}
 			}
 		} else {
 		} else {
-			d.console.Sugar().Info("Known peer (already connected):", p)
+			d.console.Debug("Known peer (already connected):", p)
 		}
 		}
 		//}(p)
 		//}(p)
 
 

+ 4 - 4
pkg/discovery/mdns.go

@@ -3,8 +3,8 @@ package discovery
 import (
 import (
 	"context"
 	"context"
 
 
+	"github.com/ipfs/go-log"
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p"
-	"go.uber.org/zap"
 
 
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/peer"
 	"github.com/libp2p/go-libp2p-core/peer"
@@ -18,7 +18,7 @@ type MDNS struct {
 // discoveryNotifee gets notified when we find a new peer via mDNS discovery
 // discoveryNotifee gets notified when we find a new peer via mDNS discovery
 type discoveryNotifee struct {
 type discoveryNotifee struct {
 	h host.Host
 	h host.Host
-	c *zap.Logger
+	c log.StandardLogger
 }
 }
 
 
 // HandlePeerFound connects to peers discovered via mDNS. Once they're connected,
 // HandlePeerFound connects to peers discovered via mDNS. Once they're connected,
@@ -28,7 +28,7 @@ func (n *discoveryNotifee) HandlePeerFound(pi peer.AddrInfo) {
 	//n.c.Infof("mDNS: discovered new peer %s\n", pi.ID.Pretty())
 	//n.c.Infof("mDNS: discovered new peer %s\n", pi.ID.Pretty())
 	err := n.h.Connect(context.Background(), pi)
 	err := n.h.Connect(context.Background(), pi)
 	if err != nil {
 	if err != nil {
-		n.c.Sugar().Warnf("mDNS: error connecting to peer %s: %s\n", pi.ID.Pretty(), err)
+		n.c.Debugf("mDNS: error connecting to peer %s: %s\n", pi.ID.Pretty(), err)
 	}
 	}
 }
 }
 
 
@@ -36,7 +36,7 @@ func (d *MDNS) Option(ctx context.Context) func(c *libp2p.Config) error {
 	return func(*libp2p.Config) error { return nil }
 	return func(*libp2p.Config) error { return nil }
 }
 }
 
 
-func (d *MDNS) Run(l *zap.Logger, ctx context.Context, host host.Host) error {
+func (d *MDNS) Run(l log.StandardLogger, ctx context.Context, host host.Host) error {
 
 
 	// setup mDNS discovery to find local peers
 	// setup mDNS discovery to find local peers
 	disc := mdns.NewMdnsService(host, d.DiscoveryServiceTag)
 	disc := mdns.NewMdnsService(host, d.DiscoveryServiceTag)

+ 3 - 3
pkg/edgevpn/config.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"context"
 	"time"
 	"time"
 
 
+	"github.com/ipfs/go-log"
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/network"
 	"github.com/libp2p/go-libp2p-core/network"
@@ -11,7 +12,6 @@ import (
 	discovery "github.com/mudler/edgevpn/pkg/discovery"
 	discovery "github.com/mudler/edgevpn/pkg/discovery"
 	hub "github.com/mudler/edgevpn/pkg/hub"
 	hub "github.com/mudler/edgevpn/pkg/hub"
 	"github.com/songgao/water"
 	"github.com/songgao/water"
-	"go.uber.org/zap"
 )
 )
 
 
 type Config struct {
 type Config struct {
@@ -39,7 +39,7 @@ type Config struct {
 	MTU              int
 	MTU              int
 	DeviceType       water.DeviceType
 	DeviceType       water.DeviceType
 	ServiceDiscovery []ServiceDiscovery
 	ServiceDiscovery []ServiceDiscovery
-	Logger           *zap.Logger
+	Logger           log.StandardLogger
 
 
 	SealKeyLength int
 	SealKeyLength int
 
 
@@ -60,7 +60,7 @@ type StreamHandler func(stream network.Stream)
 type Handler func(*hub.Message) error
 type Handler func(*hub.Message) error
 
 
 type ServiceDiscovery interface {
 type ServiceDiscovery interface {
-	Run(*zap.Logger, context.Context, host.Host) error
+	Run(log.StandardLogger, context.Context, host.Host) error
 	Option(context.Context) func(c *libp2p.Config) error
 	Option(context.Context) func(c *libp2p.Config) error
 }
 }
 
 

+ 4 - 4
pkg/edgevpn/connection.go

@@ -99,12 +99,12 @@ func (e *EdgeVPN) handleEvents(ctx context.Context) {
 		select {
 		select {
 		case m := <-e.inputCh:
 		case m := <-e.inputCh:
 			if err := m.Seal(e.sealkey()); err != nil {
 			if err := m.Seal(e.sealkey()); err != nil {
-				e.config.Logger.Sugar().Warn(err.Error())
+				e.config.Logger.Warn(err.Error())
 			}
 			}
 			e.handleOutgoingMessage(m)
 			e.handleOutgoingMessage(m)
 		case m := <-e.HubRoom.Messages:
 		case m := <-e.HubRoom.Messages:
 			if err := m.Unseal(e.sealkey()); err != nil {
 			if err := m.Unseal(e.sealkey()); err != nil {
-				e.config.Logger.Sugar().Warn(err.Error())
+				e.config.Logger.Warn(err.Error())
 			}
 			}
 			e.handleReceivedMessage(m)
 			e.handleReceivedMessage(m)
 		case <-ctx.Done():
 		case <-ctx.Done():
@@ -118,7 +118,7 @@ func (e *EdgeVPN) handleEvents(ctx context.Context) {
 func (e *EdgeVPN) handleReceivedMessage(m *hub.Message) {
 func (e *EdgeVPN) handleReceivedMessage(m *hub.Message) {
 	for _, h := range e.config.Handlers {
 	for _, h := range e.config.Handlers {
 		if err := h(m); err != nil {
 		if err := h(m); err != nil {
-			e.config.Logger.Sugar().Warnf("handler error: %s", err)
+			e.config.Logger.Warnf("handler error: %s", err)
 		}
 		}
 	}
 	}
 }
 }
@@ -126,6 +126,6 @@ func (e *EdgeVPN) handleReceivedMessage(m *hub.Message) {
 func (e *EdgeVPN) handleOutgoingMessage(m *hub.Message) {
 func (e *EdgeVPN) handleOutgoingMessage(m *hub.Message) {
 	err := e.HubRoom.PublishMessage(m)
 	err := e.HubRoom.PublishMessage(m)
 	if err != nil {
 	if err != nil {
-		e.config.Logger.Sugar().Warnf("publish error: %s", err)
+		e.config.Logger.Warnf("publish error: %s", err)
 	}
 	}
 }
 }

+ 18 - 13
pkg/edgevpn/edgevpn.go

@@ -8,6 +8,7 @@ import (
 	"runtime"
 	"runtime"
 	"time"
 	"time"
 
 
+	"github.com/ipfs/go-log"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/network"
 	"github.com/libp2p/go-libp2p-core/network"
 	"github.com/libp2p/go-libp2p-core/peer"
 	"github.com/libp2p/go-libp2p-core/peer"
@@ -58,7 +59,7 @@ func (e *EdgeVPN) Join(ledger *blockchain.Ledger) error {
 	// The ledger needs to read them and update the internal blockchain
 	// The ledger needs to read them and update the internal blockchain
 	e.config.Handlers = append(e.config.Handlers, ledger.Update)
 	e.config.Handlers = append(e.config.Handlers, ledger.Update)
 
 
-	e.config.Logger.Sugar().Info("starting edgevpn")
+	e.config.Logger.Info("starting edgevpn")
 
 
 	// Startup libp2p network
 	// Startup libp2p network
 	err := e.startNetwork()
 	err := e.startNetwork()
@@ -185,14 +186,14 @@ func (e *EdgeVPN) readPackets(ledger *blockchain.Ledger, ifce *water.Interface)
 		frame.Resize(e.config.MTU)
 		frame.Resize(e.config.MTU)
 		n, err := ifce.Read([]byte(frame))
 		n, err := ifce.Read([]byte(frame))
 		if err != nil {
 		if err != nil {
-			e.config.Logger.Sugar().Debug("could not read from interface")
+			e.config.Logger.Debug("could not read from interface")
 			return err
 			return err
 		}
 		}
 		frame = frame[:n]
 		frame = frame[:n]
 
 
 		header, err := ipv4.ParseHeader(frame)
 		header, err := ipv4.ParseHeader(frame)
 		if err != nil {
 		if err != nil {
-			e.config.Logger.Sugar().Infof("could not parase ipv4 header from frame")
+			e.config.Logger.Infof("could not parase ipv4 header from frame")
 			continue
 			continue
 		}
 		}
 
 
@@ -201,7 +202,7 @@ func (e *EdgeVPN) readPackets(ledger *blockchain.Ledger, ifce *water.Interface)
 		// Query the routing table
 		// Query the routing table
 		value, found := ledger.GetKey(MachinesLedgerKey, dst)
 		value, found := ledger.GetKey(MachinesLedgerKey, dst)
 		if !found {
 		if !found {
-			e.config.Logger.Sugar().Infof("'%s' not found in the routing table", dst)
+			e.config.Logger.Infof("'%s' not found in the routing table", dst)
 			continue
 			continue
 		}
 		}
 		machine := &types.Machine{}
 		machine := &types.Machine{}
@@ -210,14 +211,14 @@ func (e *EdgeVPN) readPackets(ledger *blockchain.Ledger, ifce *water.Interface)
 		// Decode the Peer
 		// Decode the Peer
 		d, err := peer.Decode(machine.PeerID)
 		d, err := peer.Decode(machine.PeerID)
 		if err != nil {
 		if err != nil {
-			e.config.Logger.Sugar().Infof("could not decode peer '%s'", value)
+			e.config.Logger.Infof("could not decode peer '%s'", value)
 			continue
 			continue
 		}
 		}
 
 
 		// Open a stream
 		// Open a stream
 		stream, err := e.host.NewStream(ctx, d, Protocol)
 		stream, err := e.host.NewStream(ctx, d, Protocol)
 		if err != nil {
 		if err != nil {
-			e.config.Logger.Sugar().Infof("could not open stream '%s'", err.Error())
+			e.config.Logger.Infof("could not open stream '%s'", err.Error())
 			continue
 			continue
 		}
 		}
 		stream.Write(frame)
 		stream.Write(frame)
@@ -225,13 +226,17 @@ func (e *EdgeVPN) readPackets(ledger *blockchain.Ledger, ifce *water.Interface)
 	}
 	}
 }
 }
 
 
+func (e *EdgeVPN) Logger() log.StandardLogger {
+	return e.config.Logger
+}
+
 func (e *EdgeVPN) startNetwork() error {
 func (e *EdgeVPN) startNetwork() error {
 	ctx := context.Background()
 	ctx := context.Background()
-	e.config.Logger.Sugar().Info("generating host data")
+	e.config.Logger.Info("generating host data")
 
 
 	host, err := e.genHost(ctx)
 	host, err := e.genHost(ctx)
 	if err != nil {
 	if err != nil {
-		e.config.Logger.Sugar().Error(err.Error())
+		e.config.Logger.Error(err.Error())
 		return err
 		return err
 	}
 	}
 	e.host = host
 	e.host = host
@@ -240,8 +245,8 @@ func (e *EdgeVPN) startNetwork() error {
 		host.SetStreamHandler(pid, network.StreamHandler(strh))
 		host.SetStreamHandler(pid, network.StreamHandler(strh))
 	}
 	}
 
 
-	e.config.Logger.Sugar().Info("Host created. We are:", host.ID())
-	e.config.Logger.Sugar().Info(host.Addrs())
+	e.config.Logger.Info("Host created. We are:", host.ID())
+	e.config.Logger.Info(host.Addrs())
 
 
 	// create a new PubSub service using the GossipSub router
 	// create a new PubSub service using the GossipSub router
 	ps, err := pubsub.NewGossipSub(ctx, host, pubsub.WithMaxMessageSize(e.config.MaxMessageSize))
 	ps, err := pubsub.NewGossipSub(ctx, host, pubsub.WithMaxMessageSize(e.config.MaxMessageSize))
@@ -259,13 +264,13 @@ func (e *EdgeVPN) startNetwork() error {
 
 
 	for _, sd := range e.config.ServiceDiscovery {
 	for _, sd := range e.config.ServiceDiscovery {
 		if err := sd.Run(e.config.Logger, ctx, host); err != nil {
 		if err := sd.Run(e.config.Logger, ctx, host); err != nil {
-			e.config.Logger.Sugar().Fatal(err)
+			e.config.Logger.Fatal(err)
 		}
 		}
 	}
 	}
 
 
-	e.config.Logger.Sugar().Info("starting event handler")
+	e.config.Logger.Info("starting event handler")
 	go e.handleEvents(ctx)
 	go e.handleEvents(ctx)
-	e.config.Logger.Sugar().Info("started event handler successfully")
+	e.config.Logger.Info("started event handler successfully")
 
 
 	return nil
 	return nil
 }
 }

+ 6 - 6
pkg/edgevpn/files.go

@@ -44,13 +44,13 @@ func (e *EdgeVPN) SendFile(ledger *blockchain.Ledger, fileID, filepath string) e
 	//    which connect to the given address/Port and Send what we receive from the Stream.
 	//    which connect to the given address/Port and Send what we receive from the Stream.
 	e.config.StreamHandlers[protocol.ID(FileProtocol)] = func(stream network.Stream) {
 	e.config.StreamHandlers[protocol.ID(FileProtocol)] = func(stream network.Stream) {
 		go func() {
 		go func() {
-			e.config.Logger.Sugar().Info("Received connection from", stream.Conn().RemotePeer().String())
+			e.config.Logger.Info("Received connection from", stream.Conn().RemotePeer().String())
 
 
 			// Retrieve current ID for ip in the blockchain
 			// Retrieve current ID for ip in the blockchain
 			_, found := ledger.GetKey(UsersLedgerKey, stream.Conn().RemotePeer().String())
 			_, found := ledger.GetKey(UsersLedgerKey, stream.Conn().RemotePeer().String())
 			// If mismatch, update the blockchain
 			// If mismatch, update the blockchain
 			if !found {
 			if !found {
-				e.config.Logger.Sugar().Info("Reset", stream.Conn().RemotePeer().String(), "Not found in the ledger")
+				e.config.Logger.Info("Reset", stream.Conn().RemotePeer().String(), "Not found in the ledger")
 				stream.Reset()
 				stream.Reset()
 				return
 				return
 			}
 			}
@@ -63,7 +63,7 @@ func (e *EdgeVPN) SendFile(ledger *blockchain.Ledger, fileID, filepath string) e
 
 
 			stream.Close()
 			stream.Close()
 
 
-			e.config.Logger.Sugar().Info("Done", stream.Conn().RemotePeer().String())
+			e.config.Logger.Info("Done", stream.Conn().RemotePeer().String())
 
 
 		}()
 		}()
 	}
 	}
@@ -102,7 +102,7 @@ func (e *EdgeVPN) ReceiveFile(ledger *blockchain.Ledger, fileID string, path str
 		existingValue.Unmarshal(fi)
 		existingValue.Unmarshal(fi)
 		// If mismatch, update the blockchain
 		// If mismatch, update the blockchain
 		if !found {
 		if !found {
-			e.config.Logger.Sugar().Info("file not found on blockchain")
+			e.config.Logger.Info("file not found on blockchain")
 			continue
 			continue
 		} else {
 		} else {
 			break
 			break
@@ -129,7 +129,7 @@ func (e *EdgeVPN) ReceiveFile(ledger *blockchain.Ledger, fileID string, path str
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	e.config.Logger.Sugar().Info("Saving file")
+	e.config.Logger.Info("Saving file")
 
 
 	f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
 	f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)
 	if err != nil {
 	if err != nil {
@@ -139,6 +139,6 @@ func (e *EdgeVPN) ReceiveFile(ledger *blockchain.Ledger, fileID string, path str
 	io.Copy(f, stream)
 	io.Copy(f, stream)
 
 
 	f.Close()
 	f.Close()
-	e.config.Logger.Sugar().Info("received", fileID)
+	e.config.Logger.Info("received", fileID)
 	return nil
 	return nil
 }
 }

+ 12 - 14
pkg/edgevpn/options.go

@@ -4,7 +4,7 @@ import (
 	"encoding/base64"
 	"encoding/base64"
 	"io/ioutil"
 	"io/ioutil"
 
 
-	"github.com/ipfs/go-log/v2"
+	"github.com/ipfs/go-log"
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p-core/protocol"
 	"github.com/libp2p/go-libp2p-core/protocol"
 	discovery "github.com/mudler/edgevpn/pkg/discovery"
 	discovery "github.com/mudler/edgevpn/pkg/discovery"
@@ -12,8 +12,6 @@ import (
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 	"github.com/songgao/water"
 	"github.com/songgao/water"
 	"github.com/xlzd/gotp"
 	"github.com/xlzd/gotp"
-	"go.uber.org/zap"
-	"go.uber.org/zap/zapcore"
 	"gopkg.in/yaml.v2"
 	"gopkg.in/yaml.v2"
 )
 )
 
 
@@ -81,7 +79,7 @@ func WithInterfaceName(i string) func(cfg *Config) error {
 	}
 	}
 }
 }
 
 
-func Logger(l *zap.Logger) func(cfg *Config) error {
+func Logger(l log.StandardLogger) func(cfg *Config) error {
 	return func(cfg *Config) error {
 	return func(cfg *Config) error {
 		cfg.Logger = l
 		cfg.Logger = l
 		return nil
 		return nil
@@ -168,18 +166,18 @@ func SealKeyLength(i int) func(cfg *Config) error {
 	}
 	}
 }
 }
 
 
-func LogLevel(l log.LogLevel) func(cfg *Config) error {
+func LibP2PLogLevel(l log.LogLevel) func(cfg *Config) error {
 	return func(cfg *Config) error {
 	return func(cfg *Config) error {
 		log.SetAllLoggers(l)
 		log.SetAllLoggers(l)
-		log.SetLogLevel("edgevpn", zapcore.Level(l).String())
-		log.SetLogLevel("pubsub", "fatal")
-		log.SetLogLevel("dht/RtRefreshManager", "fatal")
-		log.SetLogLevel("swarm2", "fatal")
-		log.SetLogLevel("basichost", "fatal")
-		log.SetLogLevel("relay", "fatal")
-		log.SetLogLevel("dht", "fatal")
-		log.SetLogLevel("mdns", "fatal")
-		log.SetLogLevel("net/identify", "fatal")
+		//log.SetLogLevel("edgevpn", zapcore.Level(l).String())
+		// log.SetLogLevel("pubsub", "fatal")
+		// log.SetLogLevel("dht/RtRefreshManager", "fatal")
+		// log.SetLogLevel("swarm2", "fatal")
+		// log.SetLogLevel("basichost", "fatal")
+		// log.SetLogLevel("relay", "fatal")
+		// log.SetLogLevel("dht", "fatal")
+		// log.SetLogLevel("mdns", "fatal")
+		// log.SetLogLevel("net/identify", "fatal")
 		return nil
 		return nil
 	}
 	}
 }
 }

+ 13 - 13
pkg/edgevpn/services.go

@@ -42,23 +42,23 @@ func (e *EdgeVPN) ExposeService(ledger *blockchain.Ledger, serviceID, dstaddress
 	//    which connect to the given address/Port and Send what we receive from the Stream.
 	//    which connect to the given address/Port and Send what we receive from the Stream.
 	e.config.StreamHandlers[protocol.ID(ServiceProtocol)] = func(stream network.Stream) {
 	e.config.StreamHandlers[protocol.ID(ServiceProtocol)] = func(stream network.Stream) {
 		go func() {
 		go func() {
-			e.config.Logger.Sugar().Info("Received connection from", stream.Conn().RemotePeer().String())
+			e.config.Logger.Info("Received connection from", stream.Conn().RemotePeer().String())
 
 
 			// Retrieve current ID for ip in the blockchain
 			// Retrieve current ID for ip in the blockchain
 			_, found := ledger.GetKey(UsersLedgerKey, stream.Conn().RemotePeer().String())
 			_, found := ledger.GetKey(UsersLedgerKey, stream.Conn().RemotePeer().String())
 			// If mismatch, update the blockchain
 			// If mismatch, update the blockchain
 			if !found {
 			if !found {
-				e.config.Logger.Sugar().Info("Reset", stream.Conn().RemotePeer().String(), "Not found in the ledger")
+				e.config.Logger.Info("Reset", stream.Conn().RemotePeer().String(), "Not found in the ledger")
 				stream.Reset()
 				stream.Reset()
 				return
 				return
 			}
 			}
 
 
 			// we need a list of known peers
 			// we need a list of known peers
-			e.config.Logger.Sugar().Info("Dialing", dstaddress)
+			e.config.Logger.Info("Dialing", dstaddress)
 
 
 			c, err := net.Dial("tcp", dstaddress)
 			c, err := net.Dial("tcp", dstaddress)
 			if err != nil {
 			if err != nil {
-				e.config.Logger.Sugar().Info("Reset", stream.Conn().RemotePeer().String(), err.Error())
+				e.config.Logger.Info("Reset", stream.Conn().RemotePeer().String(), err.Error())
 				stream.Reset()
 				stream.Reset()
 				return
 				return
 			}
 			}
@@ -70,7 +70,7 @@ func (e *EdgeVPN) ExposeService(ledger *blockchain.Ledger, serviceID, dstaddress
 			stream.Close()
 			stream.Close()
 			c.Close()
 			c.Close()
 
 
-			e.config.Logger.Sugar().Info("Done", stream.Conn().RemotePeer().String())
+			e.config.Logger.Info("Done", stream.Conn().RemotePeer().String())
 
 
 		}()
 		}()
 	}
 	}
@@ -82,7 +82,7 @@ func (e *EdgeVPN) ConnectToService(ledger *blockchain.Ledger, serviceID string,
 	if err != nil {
 	if err != nil {
 		return err
 		return err
 	}
 	}
-	e.config.Logger.Sugar().Info("Listening on ", srcaddr)
+	e.config.Logger.Info("Listening on ", srcaddr)
 
 
 	// Announce ourselves so nodes accepts our connection
 	// Announce ourselves so nodes accepts our connection
 	ledger.Announce(
 	ledger.Announce(
@@ -107,10 +107,10 @@ func (e *EdgeVPN) ConnectToService(ledger *blockchain.Ledger, serviceID string,
 		// Listen for an incoming connection.
 		// Listen for an incoming connection.
 		conn, err := l.Accept()
 		conn, err := l.Accept()
 		if err != nil {
 		if err != nil {
-			e.config.Logger.Sugar().Error("Error accepting: ", err.Error())
+			e.config.Logger.Error("Error accepting: ", err.Error())
 			continue
 			continue
 		}
 		}
-		e.config.Logger.Sugar().Info("New connection from", l.Addr().String())
+		e.config.Logger.Info("New connection from", l.Addr().String())
 		// Handle connections in a new goroutine, forwarding to the p2p service
 		// Handle connections in a new goroutine, forwarding to the p2p service
 		go func() {
 		go func() {
 			// Retrieve current ID for ip in the blockchain
 			// Retrieve current ID for ip in the blockchain
@@ -119,23 +119,23 @@ func (e *EdgeVPN) ConnectToService(ledger *blockchain.Ledger, serviceID string,
 			existingValue.Unmarshal(service)
 			existingValue.Unmarshal(service)
 			// If mismatch, update the blockchain
 			// If mismatch, update the blockchain
 			if !found {
 			if !found {
-				e.config.Logger.Sugar().Info("service not found on blockchain")
+				e.config.Logger.Info("service not found on blockchain")
 				return
 				return
 			}
 			}
 			// Decode the Peer
 			// Decode the Peer
 			d, err := peer.Decode(service.PeerID)
 			d, err := peer.Decode(service.PeerID)
 			if err != nil {
 			if err != nil {
-				e.config.Logger.Sugar().Infof("could not decode peer '%s'", service.PeerID)
+				e.config.Logger.Infof("could not decode peer '%s'", service.PeerID)
 				return
 				return
 			}
 			}
 
 
 			// Open a stream
 			// Open a stream
 			stream, err := e.host.NewStream(context.Background(), d, ServiceProtocol)
 			stream, err := e.host.NewStream(context.Background(), d, ServiceProtocol)
 			if err != nil {
 			if err != nil {
-				e.config.Logger.Sugar().Infof("could not open stream '%s'", err.Error())
+				e.config.Logger.Infof("could not open stream '%s'", err.Error())
 				return
 				return
 			}
 			}
-			e.config.Logger.Sugar().Info("Redirecting", l.Addr().String(), "to", serviceID)
+			e.config.Logger.Info("Redirecting", l.Addr().String(), "to", serviceID)
 
 
 			closer := make(chan struct{}, 2)
 			closer := make(chan struct{}, 2)
 			go copyStream(closer, stream, conn)
 			go copyStream(closer, stream, conn)
@@ -144,7 +144,7 @@ func (e *EdgeVPN) ConnectToService(ledger *blockchain.Ledger, serviceID string,
 
 
 			stream.Close()
 			stream.Close()
 			conn.Close()
 			conn.Close()
-			e.config.Logger.Sugar().Info("Done handling", l.Addr().String(), "to", serviceID)
+			e.config.Logger.Info("Done handling", l.Addr().String(), "to", serviceID)
 		}()
 		}()
 	}
 	}
 }
 }

+ 114 - 0
pkg/logger/logger.go

@@ -0,0 +1,114 @@
+package logger
+
+import (
+	"fmt"
+	"os"
+
+	terminal "github.com/mudler/go-isterminal"
+
+	"github.com/ipfs/go-log"
+	"github.com/pterm/pterm"
+)
+
+var _ log.StandardLogger = &Logger{}
+
+type Logger struct {
+	level log.LogLevel
+}
+
+func New(lvl log.LogLevel) *Logger {
+	if !terminal.IsTerminal(os.Stdout) {
+		pterm.DisableColor()
+	}
+	if lvl == log.LevelDebug {
+		pterm.EnableDebugMessages()
+	}
+	return &Logger{level: lvl}
+}
+
+func joinMsg(args ...interface{}) (message string) {
+	for _, m := range args {
+		message += " " + fmt.Sprintf("%v", m)
+	}
+	return
+}
+
+func (l Logger) enabled(lvl log.LogLevel) bool {
+	return lvl >= l.level
+}
+
+func (l Logger) Debug(args ...interface{}) {
+	if l.enabled(log.LevelDebug) {
+		pterm.Debug.Println(joinMsg(args...))
+	}
+}
+
+func (l Logger) Debugf(f string, args ...interface{}) {
+	if l.enabled(log.LevelDebug) {
+		pterm.Debug.Printfln(f, args...)
+	}
+}
+
+func (l Logger) Error(args ...interface{}) {
+	if l.enabled(log.LevelError) {
+		pterm.Error.Println(pterm.LightRed(joinMsg(args...)))
+	}
+}
+
+func (l Logger) Errorf(f string, args ...interface{}) {
+	if l.enabled(log.LevelError) {
+		pterm.Error.Printfln(pterm.LightRed(f), args...)
+	}
+}
+
+func (l Logger) Fatal(args ...interface{}) {
+	if l.enabled(log.LevelFatal) {
+		pterm.Fatal.Println(pterm.Red(joinMsg(args...)))
+	}
+}
+
+func (l Logger) Fatalf(f string, args ...interface{}) {
+	if l.enabled(log.LevelFatal) {
+		pterm.Fatal.Printfln(pterm.Red(joinMsg(args...)))
+	}
+}
+
+func (l Logger) Info(args ...interface{}) {
+	if l.enabled(log.LevelInfo) {
+		pterm.Info.Println(pterm.LightBlue(joinMsg(args...)))
+	}
+}
+
+func (l Logger) Infof(f string, args ...interface{}) {
+	if l.enabled(log.LevelInfo) {
+		pterm.Info.Printfln(pterm.LightBlue(joinMsg(args...)))
+	}
+}
+
+func (l Logger) Panic(args ...interface{}) {
+	l.Fatal(args...)
+}
+
+func (l Logger) Panicf(f string, args ...interface{}) {
+	l.Fatalf(f, args...)
+}
+
+func (l Logger) Warn(args ...interface{}) {
+	if l.enabled(log.LevelWarn) {
+		pterm.Warning.Println(pterm.LightYellow(joinMsg(args...)))
+	}
+}
+
+func (l Logger) Warnf(f string, args ...interface{}) {
+	if l.enabled(log.LevelWarn) {
+		pterm.Warning.Printfln(pterm.LightYellow(joinMsg(args...)))
+	}
+}
+
+func (l Logger) Warning(args ...interface{}) {
+	l.Warn(args...)
+}
+
+func (l Logger) Warningf(f string, args ...interface{}) {
+	l.Warnf(f, args...)
+}