MCPcopy
hub / github.com/cloudfoundry/cli / NewLogger

Function NewLogger

cf/trace/logger_provider.go:12–46  ·  view source on GitHub ↗
(writer io.Writer, verbose bool, boolsOrPaths ...string)

Source from the content-addressed store, hash-verified

10)
11
12func NewLogger(writer io.Writer, verbose bool, boolsOrPaths ...string) Printer {
13 LoggingToStdout = verbose
14
15 var printers []Printer
16
17 stdoutLogger := NewWriterPrinter(writer, true)
18
19 for _, path := range boolsOrPaths {
20 b, err := strconv.ParseBool(path)
21 LoggingToStdout = LoggingToStdout || b
22
23 if path != "" && err != nil {
24 var file *os.File
25 err = os.MkdirAll(filepath.Dir(path), os.ModeDir|os.ModePerm)
26 if err == nil {
27 file, err = os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
28 }
29
30 if err == nil {
31 printers = append(printers, NewWriterPrinter(file, false))
32 } else {
33 stdoutLogger.Printf(T("CF_TRACE ERROR CREATING LOG FILE {{.Path}}:\n{{.Err}}",
34 map[string]interface{}{"Path": path, "Err": err}))
35
36 LoggingToStdout = true
37 }
38 }
39 }
40
41 if LoggingToStdout {
42 printers = append(printers, stdoutLogger)
43 }
44
45 return CombinePrinters(printers)
46}

Callers 3

NewRPCServiceFunction · 0.92
MainFunction · 0.92

Calls 3

NewWriterPrinterFunction · 0.85
CombinePrintersFunction · 0.85
PrintfMethod · 0.65

Tested by

no test coverage detected