github.com/newrelic/newrelic-client-go@v1.1.0/pkg/logs/example_log_test.go (about) 1 //go:build integration 2 // +build integration 3 4 package logs 5 6 import ( 7 "fmt" 8 "log" 9 "os" 10 "testing" 11 12 "github.com/newrelic/newrelic-client-go/pkg/config" 13 ) 14 15 func Example_log(t *testing.T) { 16 // Initialize the client configuration. A New Relic License Key is required 17 // to communicate with the backend API. 18 cfg := config.New() 19 cfg.LicenseKey = os.Getenv("NEW_RELIC_LICENSE_KEY") 20 cfg.LogLevel = "trace" 21 cfg.Compression = config.Compression.None 22 23 // Initialize the client. 24 client := New(cfg) 25 26 logEntry := struct { 27 Message string `json:"message"` 28 }{ 29 Message: "INFO: From example_log_test.go", 30 } 31 32 // Post a Log entry 33 if err := client.CreateLogEntry(logEntry); err != nil { 34 log.Fatal("error posting Log entry: ", err) 35 } 36 37 fmt.Printf("success") 38 }