Пример #1
0
func (s *MySuite) BenchmarkLogexWriteVariadicToNullFile(c *C) {
	f, err := os.OpenFile("/dev/null",
		os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	c.Assert(err, IsNil)
	c.Assert(f, NotNil)
	defer f.Close()
	logex.SetOutput(f)

	for i := 0; i < c.N; i++ {
		logex.Fatal("hello %v %v", "abc", 123)
	}
}
Пример #2
0
func (s *MySuite) TestLogLevel(c *C) {
	var b bytes.Buffer
	logex.SetOutput(&b)
	logex.SetLevel(logex.FATAL)

	logex.Debug("hello")
	logex.Trace("world")
	logex.Info("hi")
	logex.Warn("blabla")
	c.Assert(b.Len(), Equals, 0)

	logex.Fatal("fatal")
	c.Log(b.String())
	c.Assert(b.Len(), Not(Equals), 0)
}
Пример #3
0
func (s *MySuite) BenchmarkLogexWriteStringToNullFile(c *C) {
	f, err := os.OpenFile("/dev/null",
		os.O_TRUNC|os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	c.Assert(err, IsNil)
	c.Assert(f, NotNil)
	defer f.Close()
	logex.SetOutput(f)

	arr := []string{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"bHHHHHHHHHHHbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
		"cccccccccccccccccccccccccccccccccccccc",
		"eeUUUUUUeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeUUUUUUUUUUeeeeeeeeeeeeeeeee",
		"ffffffffXXXXXfffffffffffffffffffffffffffffffffffffffffxxxxxxxxxffff"}
	for i := 0; i < c.N; i++ {
		s := arr[i%len(arr)]
		logex.Fatal(s)
	}
}