initLoggingWithCmdParameters initializes logging considering if cli version specifics
(logLevelPtr *string, cmd bool)
| 258 | |
| 259 | // initLoggingWithCmdParameters initializes logging considering if cli version specifics |
| 260 | func 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 | } |
no test coverage detected