コード例 #1
0
ファイル: neighbor_test.go プロジェクト: jmptrader/Tecellate
func initLogs(name string, t *testing.T) func() {
	// Show all output if test fails
	logflow.NewSink(logflow.NewTestWriter(t), ".*")

	err := os.MkdirAll("logs/neighbor_test", 0776)
	if err != nil {
		panic("Directory logs/neighbor_test could not be created.")
	}

	logflow.FileSink("logs/neighbor_test/all", true, ".*")
	logflow.FileSink("logs/neighbor_test/"+name, true, ".*")
	logflow.FileSink("logs/neighbor_test/debug", true, ".*/debug")

	// Or show all output anyway I guess...
	// logflow.StdoutSink(".*")
	//     logflow.StdoutSink(".*/debug")

	defer logflow.Println("test", fmt.Sprintf(`
--------------------------------------------------------------------------------
    Start Testing %v
`, name))
	return func() {
		logflow.Println("test", fmt.Sprintf(`
--------------------------------------------------------------------------------
        End Testing %v
    `, name))
		logflow.RemoveAllSinks()
	}
}
コード例 #2
0
ファイル: logging.go プロジェクト: jmptrader/Tecellate
func InitLogs(name string, t *testing.T) (closer func()) {
	fmt.Println("    -", name)

	// Show all output if test fails
	writer := logflow.NewTestWriter(t)
	snk, _ := logflow.NewSink(writer, ".*")

	err := os.MkdirAll("logs/wifi", 0776)
	if err != nil {
		panic("Directory logs/wifi could not be created.")
	}
	//     logflow.FileSink("logs/wifi/test/" + name, true, ".*")
	//     logflow.StdoutSink("agent/wifi.*")

	//     log = func(v ...interface{}) {
	//         logflow.Println(fmt.Sprintf("test/%v", name), v...)
	//     }

	defer func() {
		logflow.WriteToSinksFunction = func(keypath, s string) {
			if strings.HasPrefix(keypath, "agent/wifi") {
				//                 fmt.Println(keypath, s)
				snk.Write(keypath, s)
			} else if strings.HasPrefix(keypath, fmt.Sprintf("test/%v", name)) {
				snk.Write(keypath, s)
			} else if strings.HasPrefix(keypath, "coord") {
				//                 snk.Write(keypath, s)
			}
		}
		writer.Write([]byte(fmt.Sprintf(`

    - Start Testing %v
--------------------------------------------------------------------------------`, name)))
	}()

	closer = func() {
		writer.Write([]byte(fmt.Sprintf(
			`--------------------------------------------------------------------------------
    - End Testing %v

`, name)))
		logflow.RemoveAllSinks()
		logflow.WriteToSinksFunction = write_to_sinks
	}
	return closer
}