go.undefinedlabs.com/scopeagent@v0.4.2/instrumentation/logrus/hook_test.go (about) 1 package logrus 2 3 import ( 4 "github.com/sirupsen/logrus" 5 "os" 6 "testing" 7 8 "go.undefinedlabs.com/scopeagent" 9 "go.undefinedlabs.com/scopeagent/agent" 10 "go.undefinedlabs.com/scopeagent/tracer" 11 ) 12 13 var r *tracer.InMemorySpanRecorder 14 15 func TestMain(m *testing.M) { 16 // Test tracer 17 r = tracer.NewInMemoryRecorder() 18 os.Exit(scopeagent.Run(m, agent.WithRecorders(r))) 19 } 20 21 func TestLogrus(t *testing.T) { 22 ctx := scopeagent.GetContextFromTest(t) 23 r.Reset() 24 25 logger := logrus.New() 26 logger.SetLevel(logrus.TraceLevel) 27 logger.SetReportCaller(true) 28 AddScopeHook(logger) 29 30 logger.WithContext(ctx).WithField("Data", "Value").Error("Error message") 31 logger.WithContext(ctx).WithField("Data", "Value").Warn("Warning message") 32 logger.WithContext(ctx).WithField("Data", "Value").Info("Info message") 33 logger.WithContext(ctx).WithField("Data", "Value").Debug("Debug message") 34 logger.WithContext(ctx).WithField("Data", "Value").Trace("Trace message") 35 }