// 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.") }
// 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.") }
// 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.") }
// 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.") }
// 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.") }
// 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!") }
func setupLogger(level int) { logger := applog.GoLogger{} applog.SetLevel(level) applog.SetLogger(logger) }