github.com/safing/portbase@v0.19.5/log/logging_test.go (about) 1 package log 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 ) 8 9 func init() { 10 err := Start() 11 if err != nil { 12 panic(fmt.Sprintf("start failed: %s", err)) 13 } 14 } 15 16 func TestLogging(t *testing.T) { 17 t.Parallel() 18 19 // skip 20 if testing.Short() { 21 t.Skip() 22 } 23 24 // set levels (static random) 25 SetLogLevel(WarningLevel) 26 SetLogLevel(InfoLevel) 27 SetLogLevel(ErrorLevel) 28 SetLogLevel(DebugLevel) 29 SetLogLevel(CriticalLevel) 30 SetLogLevel(TraceLevel) 31 32 // log 33 Trace("Trace") 34 Debug("Debug") 35 Info("Info") 36 Warning("Warning") 37 Error("Error") 38 Critical("Critical") 39 40 // logf 41 Tracef("Trace %s", "f") 42 Debugf("Debug %s", "f") 43 Infof("Info %s", "f") 44 Warningf("Warning %s", "f") 45 Errorf("Error %s", "f") 46 Criticalf("Critical %s", "f") 47 48 // play with levels 49 SetLogLevel(CriticalLevel) 50 Warning("Warning") 51 SetLogLevel(TraceLevel) 52 53 // log invalid level 54 log(0xFF, "msg", nil) 55 56 // wait logs to be written 57 time.Sleep(1 * time.Millisecond) 58 59 // just for show 60 UnSetPkgLevels() 61 62 // do not really shut down, we may need logging for other tests 63 // ShutdownLogging() 64 }