Ejemplo n.º 1
0
func (s *MySuite) TestExample(c *C) {
	// this is not a real test case, just usage & output examples
	logex.Debug("hello world, this is debug log")
	logex.Trace("hi, this is trace log")
	logex.Info("how're you doing, this is info log")
	logex.Warn("Warning! Warning!")
	logex.Fatal("Critical error or fatal!")
}
Ejemplo n.º 2
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)
	}
}
Ejemplo n.º 3
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)
}
Ejemplo n.º 4
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)
	}
}