Refactor logger (#1185)
* refactor: logger * refactor: logging * refactor: rename func * refactor: logging * refactor: logging format
This commit is contained in:
@@ -12,9 +12,8 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
conf "github.com/future-architect/vuls/config"
|
||||
"github.com/future-architect/vuls/util"
|
||||
"github.com/future-architect/vuls/logging"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type execResult struct {
|
||||
@@ -72,7 +71,7 @@ func parallelExec(fn func(osTypeInterface) error, timeoutSec ...int) {
|
||||
go func(s osTypeInterface) {
|
||||
defer func() {
|
||||
if p := recover(); p != nil {
|
||||
util.Log.Debugf("Panic: %s on %s",
|
||||
logging.Log.Debugf("Panic: %s on %s",
|
||||
p, s.getServerInfo().GetServerName())
|
||||
}
|
||||
}()
|
||||
@@ -100,7 +99,7 @@ func parallelExec(fn func(osTypeInterface) error, timeoutSec ...int) {
|
||||
if len(s.getErrs()) == 0 {
|
||||
successes = append(successes, s)
|
||||
} else {
|
||||
util.Log.Errorf("Error on %s, err: %+v",
|
||||
logging.Log.Errorf("Error on %s, err: %+v",
|
||||
s.getServerInfo().GetServerName(), s.getErrs())
|
||||
errServers = append(errServers, s)
|
||||
}
|
||||
@@ -121,9 +120,8 @@ func parallelExec(fn func(osTypeInterface) error, timeoutSec ...int) {
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
err := xerrors.Errorf("Timed out: %s",
|
||||
s.getServerInfo().GetServerName())
|
||||
util.Log.Errorf("%+v", err)
|
||||
err := xerrors.Errorf("Timed out: %s", s.getServerInfo().GetServerName())
|
||||
logging.Log.Errorf("%+v", err)
|
||||
s.setErrs([]error{err})
|
||||
errServers = append(errServers, s)
|
||||
}
|
||||
@@ -133,7 +131,7 @@ func parallelExec(fn func(osTypeInterface) error, timeoutSec ...int) {
|
||||
return
|
||||
}
|
||||
|
||||
func exec(c conf.ServerInfo, cmd string, sudo bool, log ...*logrus.Entry) (result execResult) {
|
||||
func exec(c conf.ServerInfo, cmd string, sudo bool, log ...logging.Logger) (result execResult) {
|
||||
logger := getSSHLogger(log...)
|
||||
logger.Debugf("Executing... %s", strings.Replace(cmd, "\n", "", -1))
|
||||
|
||||
@@ -143,7 +141,7 @@ func exec(c conf.ServerInfo, cmd string, sudo bool, log ...*logrus.Entry) (resul
|
||||
result = sshExecExternal(c, cmd, sudo)
|
||||
}
|
||||
|
||||
logger.Debug(result)
|
||||
logger.Debugf("%+v", result)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -261,9 +259,9 @@ func sshExecExternal(c conf.ServerInfo, cmd string, sudo bool) (result execResul
|
||||
return
|
||||
}
|
||||
|
||||
func getSSHLogger(log ...*logrus.Entry) *logrus.Entry {
|
||||
func getSSHLogger(log ...logging.Logger) logging.Logger {
|
||||
if len(log) == 0 {
|
||||
return util.Log
|
||||
return logging.Log
|
||||
}
|
||||
return log[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user