Skip to content

Commit

Permalink
fix: log setter overwrite
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Buchleitner <[email protected]>
  • Loading branch information
mabunixda committed Sep 4, 2024
1 parent c402157 commit 37747c7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion wattpilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"time"

"github.com/sirupsen/logrus"
logruswriter "github.com/sirupsen/logrus/hooks/writer"

"golang.org/x/crypto/pbkdf2"
"nhooyr.io/websocket"
)
Expand Down Expand Up @@ -117,8 +119,17 @@ func New(host string, password string) *Wattpilot {

}
func (w *Wattpilot) SetLogger(logger *log.Logger) {
w.logger.SetOutput(logger.Writer())
w.logger.SetFormatter(&logrus.TextFormatter{})

w.logger.AddHook(&logruswriter.Hook{
Writer: logger.Writer(),
LogLevels: []logrus.Level{
logrus.PanicLevel,
logrus.FatalLevel,
logrus.ErrorLevel,
logrus.WarnLevel,
},
})
}

func (w *Wattpilot) SetLogLevel(level logrus.Level) {
Expand Down

0 comments on commit 37747c7

Please sign in to comment.