-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_provider.go
42 lines (30 loc) · 911 Bytes
/
logger_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package trace
import (
"io"
"strconv"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/gofileutils/fileutils"
)
func NewLogger(writer io.Writer, verbose bool, cf_trace, config_trace string) Printer {
LoggingToStdout = verbose
var printers []Printer
stdoutLogger := NewWriterPrinter(writer, true)
for _, path := range []string{cf_trace, config_trace} {
b, err := strconv.ParseBool(path)
LoggingToStdout = LoggingToStdout || b
if path != "" && err != nil {
file, err := fileutils.Open(path)
if err == nil {
printers = append(printers, NewWriterPrinter(file, false))
} else {
stdoutLogger.Printf(T("CF_TRACE ERROR CREATING LOG FILE {{.Path}}:\n{{.Err}}",
map[string]interface{}{"Path": path, "Err": err}))
LoggingToStdout = true
}
}
}
if LoggingToStdout {
printers = append(printers, stdoutLogger)
}
return CombinePrinters(printers)
}