No warning(s) in the output file with -quiet option. Report command (#885)
This commit is contained in:
		@@ -87,6 +87,7 @@ func (*ReportCmd) Usage() string {
 | 
			
		||||
		[-http-proxy=http://192.168.0.1:8080]
 | 
			
		||||
		[-debug]
 | 
			
		||||
		[-debug-sql]
 | 
			
		||||
		[-quiet]
 | 
			
		||||
		[-pipe]
 | 
			
		||||
		[-cvedb-type=sqlite3|mysql|postgres|redis|http]
 | 
			
		||||
		[-cvedb-sqlite3-path=/path/to/cve.sqlite3]
 | 
			
		||||
@@ -112,6 +113,8 @@ func (p *ReportCmd) SetFlags(f *flag.FlagSet) {
 | 
			
		||||
	f.BoolVar(&c.Conf.Debug, "debug", false, "debug mode")
 | 
			
		||||
	f.BoolVar(&c.Conf.DebugSQL, "debug-sql", false, "SQL debug mode")
 | 
			
		||||
 | 
			
		||||
	f.BoolVar(&c.Conf.Quiet, "quiet", false, "Quiet mode. No output on stdout")
 | 
			
		||||
 | 
			
		||||
	wd, _ := os.Getwd()
 | 
			
		||||
	defaultConfPath := filepath.Join(wd, "config.toml")
 | 
			
		||||
	f.StringVar(&p.configPath, "config", defaultConfPath, "/path/to/toml")
 | 
			
		||||
 
 | 
			
		||||
@@ -106,6 +106,7 @@ type Config struct {
 | 
			
		||||
	LogDir     string `json:"logDir,omitempty"`
 | 
			
		||||
	ResultsDir string `json:"resultsDir,omitempty"`
 | 
			
		||||
	Pipe       bool   `json:"pipe,omitempty"`
 | 
			
		||||
	Quiet      bool   `json:"quiet,omitempty"`
 | 
			
		||||
 | 
			
		||||
	Default       ServerInfo            `json:"default,omitempty"`
 | 
			
		||||
	Servers       map[string]ServerInfo `json:"servers,omitempty"`
 | 
			
		||||
 
 | 
			
		||||
@@ -104,6 +104,10 @@ func formatOneLineSummary(rs ...models.ScanResult) string {
 | 
			
		||||
				r.FormatServerName(), r.Warnings))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	// We don't want warning message to the summary file
 | 
			
		||||
	if config.Conf.Quiet {
 | 
			
		||||
		return fmt.Sprintf("%s\n", table)
 | 
			
		||||
	}
 | 
			
		||||
	return fmt.Sprintf("%s\n\n%s", table, strings.Join(
 | 
			
		||||
		warnMsgs, "\n\n"))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user