docs(logging): add example for logging the HTTPRequest type (#3097)
* docs(logging): add example for logging the HTTPRequest type
* ci(logging): go fmt examples_test.go
diff --git a/logging/examples_test.go b/logging/examples_test.go
index b9623ee..4ff423d 100644
--- a/logging/examples_test.go
+++ b/logging/examples_test.go
@@ -18,6 +18,7 @@
"context"
"encoding/json"
"fmt"
+ "net/http"
"os"
"cloud.google.com/go/logging"
@@ -86,6 +87,23 @@
_ = lg // TODO: use the Logger.
}
+func ExampleHTTPRequest() {
+ ctx := context.Background()
+ client, err := logging.NewClient(ctx, "my-project")
+ if err != nil {
+ // TODO: Handle error.
+ }
+ lg := client.Logger("my-log")
+ httpEntry := logging.Entry{
+ Payload: "optional message",
+ HTTPRequest: &logging.HTTPRequest{
+ // TODO: pass in request
+ Request: &http.Request{},
+ },
+ }
+ lg.Log(httpEntry)
+}
+
func ExampleLogger_LogSync() {
ctx := context.Background()
client, err := logging.NewClient(ctx, "my-project")