예제 #1
0
func NewLogger(writer io.Writer, verbose bool, cfTrace, configTrace string) Printer {
	LoggingToStdout = verbose

	var printers []Printer

	stdoutLogger := NewWriterPrinter(writer, true)

	for _, path := range []string{cfTrace, configTrace} {
		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)
}
예제 #2
0
파일: trace.go 프로젝트: palakmathur/cli
func newFileLogger(path string) Printer {
	file, err := fileutils.Open(path)
	if err != nil {
		logger := newStdoutLogger()
		logger.Printf("CF_TRACE ERROR CREATING LOG FILE %s:\n%s", path, err)
		return logger
	}

	return log.New(file, "", 0)
}
예제 #3
0
파일: trace.go 프로젝트: hail100/cli
func newFileLogger(path string) Printer {
	file, err := fileutils.Open(path)
	if err != nil {
		logger := newStdoutLogger()
		logger.Printf(T("CF_TRACE ERROR CREATING LOG FILE {{.Path}}:\n{{.Err}}",
			map[string]interface{}{"Path": path, "Err": err}))
		return logger
	}

	return log.New(file, "", 0)
}
예제 #4
0
	. "github.com/onsi/gomega"
)

var _ = Describe("Fileutils File", func() {
	var fixturePath = filepath.Clean("../fixtures/fileutils/supervirus.zsh")
	var fixtureBytes []byte

	BeforeEach(func() {
		var err error
		fixtureBytes, err = ioutil.ReadFile(fixturePath)
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("Open", func() {
		It("opens an existing file", func() {
			fd, err := fileutils.Open(fixturePath)
			Expect(err).NotTo(HaveOccurred())

			fileBytes, err := ioutil.ReadAll(fd)
			Expect(err).NotTo(HaveOccurred())
			fd.Close()

			Expect(fileBytes).To(Equal(fixtureBytes))
		})

		It("creates a non-existing file and all intermediary directories", func() {
			filePath := fileutils.TempPath("open_test")

			fd, err := fileutils.Open(filePath)
			Expect(err).NotTo(HaveOccurred())