No warning(s) in the output file with -quiet option. Report command (#885)

This commit is contained in:
DjinnS
2019-08-25 03:56:42 +02:00
committed by Kota Kanbe
parent d5e2040cef
commit dec5d3b165
4 changed files with 20 additions and 1 deletions

View File

@@ -44,7 +44,6 @@ func init() {
func NewCustomLogger(c config.ServerInfo) *logrus.Entry {
log := logrus.New()
log.Formatter = &formatter.TextFormatter{MsgAnsiColor: c.LogMsgAnsiColor}
log.Out = os.Stderr
log.Level = logrus.InfoLevel
if config.Conf.Debug {
log.Level = logrus.DebugLevel
@@ -62,6 +61,18 @@ func NewCustomLogger(c config.ServerInfo) *logrus.Entry {
}
}
// Only log to a file if quiet mode enabled
if config.Conf.Quiet {
logFile := logDir + "/vuls.log"
if file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644); err == nil {
log.Out = file
} else {
log.Errorf("Failed to create log file. path: %s, err: %s", logFile, err)
}
} else {
log.Out = os.Stderr
}
whereami := "localhost"
if 0 < len(c.ServerName) {
whereami = c.GetServerName()