Skip to content

Commit

Permalink
🔊 Add level and timestamp to port-forward handler logs
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Mar 28, 2022
1 parent a132b6d commit 04305b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/port_forward/port_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/clevyr/kubedb/internal/config"
"github.com/clevyr/kubedb/internal/config/flags"
log2 "github.com/clevyr/kubedb/internal/log"
"github.com/clevyr/kubedb/internal/util"
"github.com/jedib0t/go-pretty/v6/table"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -87,7 +88,9 @@ func run(cmd *cobra.Command, args []string) (err error) {
ports := []string{fmt.Sprintf("%d:%d", conf.LocalPort, conf.Grammar.DefaultPort())}
stopCh := make(chan struct{}, 1)
readyCh := make(chan struct{}, 1)
fw, err := portforward.NewOnAddresses(dialer, conf.Addresses, ports, stopCh, readyCh, os.Stdout, os.Stderr)
outWriter := log2.NewWriter(log.StandardLogger(), log.InfoLevel)
errWriter := log2.NewWriter(log.StandardLogger(), log.ErrorLevel)
fw, err := portforward.NewOnAddresses(dialer, conf.Addresses, ports, stopCh, readyCh, outWriter, errWriter)
if err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions internal/log/log_writer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package log

import log "github.com/sirupsen/logrus"

func NewWriter(logger *log.Logger, level log.Level) Writer {
return Writer{
logger: logger,
level: level,
}
}

type Writer struct {
logger *log.Logger
level log.Level
}

func (l Writer) Write(p []byte) (n int, err error) {
l.logger.Log(l.level, string(p))
return len(p), nil
}

0 comments on commit 04305b0

Please sign in to comment.