align log level across plugins

happy lint

happy lint
This commit is contained in:
Boshi Lian 2022-08-05 22:00:47 +00:00
parent d3ec47f4ec
commit 319824e564
13 changed files with 286 additions and 230 deletions

View file

@ -2,6 +2,7 @@ package libplugin
import (
"fmt"
"io"
"net"
"strconv"
@ -40,8 +41,16 @@ func ConfigStdioLogrus(p SshPiperPlugin, logger *logrus.Logger) {
if logger == nil {
logger = logrus.StandardLogger()
}
logger.SetOutput(p.GetLoggerOutput())
logger.SetFormatter(&logrus.TextFormatter{ForceColors: true})
p.SetConfigLoggerCallback(func(w io.Writer, level string, tty bool) {
logger.SetOutput(w)
lv, _ := logrus.ParseLevel(level)
logger.SetLevel(lv)
if tty {
logger.SetFormatter(&logrus.TextFormatter{ForceColors: true})
}
})
}
// SplitHostPortForSSH is the modified version of net.SplitHostPort but return port 22 is no port is specified