github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/lib/log/cmdlogger/impl.go (about)

     1  package cmdlogger
     2  
     3  import (
     4  	"flag"
     5  	"log"
     6  
     7  	"github.com/Cloud-Foundations/Dominator/lib/log/debuglogger"
     8  )
     9  
    10  func init() {
    11  	flag.BoolVar(&stdOptions.Datestamps, "logDatestamps", false,
    12  		"If true, prefix logs with datestamps")
    13  	flag.IntVar(&stdOptions.DebugLevel, "logDebugLevel", -1, "Debug log level")
    14  	flag.BoolVar(&stdOptions.Subseconds, "logSubseconds", false,
    15  		"If true, datestamps will have subsecond resolution")
    16  }
    17  
    18  func newLogger(options Options) *debuglogger.Logger {
    19  	if options.DebugLevel < -1 {
    20  		options.DebugLevel = -1
    21  	}
    22  	if options.DebugLevel > 65535 {
    23  		options.DebugLevel = 65535
    24  	}
    25  	logFlags := 0
    26  	if options.Datestamps {
    27  		logFlags |= log.LstdFlags
    28  		if options.Subseconds {
    29  			logFlags |= log.Lmicroseconds
    30  		}
    31  	}
    32  	logger := debuglogger.New(log.New(options.Writer, "", logFlags))
    33  	logger.SetLevel(int16(options.DebugLevel))
    34  	return logger
    35  }