MCPcopy
hub / github.com/hardentools/hardentools / initLoggingWithCmdParameters

Function initLoggingWithCmdParameters

utils.go:260–287  ·  view source on GitHub ↗

initLoggingWithCmdParameters initializes logging considering if cli version specifics

(logLevelPtr *string, cmd bool)

Source from the content-addressed store, hash-verified

258
259// initLoggingWithCmdParameters initializes logging considering if cli version specifics
260func initLoggingWithCmdParameters(logLevelPtr *string, cmd bool) {
261 var logfile *os.File
262 var err error
263
264 if cmd {
265 // command line only => use stdout
266 logfile = os.Stdout
267 } else {
268 // UI => use logfile
269 logfile, err = os.Create(logPath)
270 if err != nil {
271 panic(err)
272 }
273 }
274 if strings.EqualFold(*logLevelPtr, "Info") {
275 // only standard log output
276 initLogging(ioutil.Discard, logfile, !cmd)
277 } else if strings.EqualFold(*logLevelPtr, "Trace") {
278 // standard + trace logging
279 initLogging(logfile, logfile, !cmd)
280 } else if strings.EqualFold(*logLevelPtr, "Off") {
281 // no logging
282 initLogging(ioutil.Discard, ioutil.Discard, !cmd)
283 } else {
284 // default logging (only standard log output)
285 initLogging(ioutil.Discard, logfile, !cmd)
286 }
287}

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 1

initLoggingFunction · 0.85

Tested by

no test coverage detected