示例#1
0
// Test log level.
func TestLevel(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)

	applog.SetLevel(applog.LevelDebug)
	assert.Equal(applog.Level(), applog.LevelDebug, "Level debug.")
	applog.SetLevel(applog.LevelCritical)
	assert.Equal(applog.Level(), applog.LevelCritical, "Level critical.")
	applog.SetLevel(applog.LevelDebug)
	assert.Equal(applog.Level(), applog.LevelDebug, "Level debug.")
}
示例#2
0
// Test logging from level warning and above.
func TestWarningAndAbove(t *testing.T) {
	applog.SetLevel(applog.LevelWarning)

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")
}
示例#3
0
// Test log at all levels.
func TestAllLevels(t *testing.T) {
	applog.SetLevel(applog.LevelDebug)

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")
}
示例#4
0
// Test logging with the go logger.
func TestGoLogger(t *testing.T) {
	log.SetOutput(os.Stdout)

	applog.SetLevel(applog.LevelDebug)
	applog.SetLogger(applog.GoLogger{})

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")
}
示例#5
0
// Test logging with an own logger.
func TestOwnLogger(t *testing.T) {
	assert := asserts.NewTestingAsserts(t, true)
	ownLogger := &testLogger{[]string{}}

	applog.SetLevel(applog.LevelDebug)
	applog.SetLogger(ownLogger)

	applog.Debugf("Debug.")
	applog.Infof("Info.")
	applog.Warningf("Warning.")
	applog.Errorf("Error.")
	applog.Criticalf("Critical.")

	assert.Length(ownLogger.logs, 5, "Everything logged.")
}
示例#6
0
// Test debugging.
func TestDebug(t *testing.T) {
	applog.Debugf("Hello, I'm debugging %v!", "here")
	applog.SetLevel(applog.LevelError)
	applog.Debugf("Should not be shown!")
}
示例#7
0
func setupLogger(level int) {
	logger := applog.GoLogger{}
	applog.SetLevel(level)
	applog.SetLogger(logger)
}