From 925033712191bce44fa99eb117d6531106042272 Mon Sep 17 00:00:00 2001 From: Nicole Zhu <69952136+nicoleczhu@users.noreply.github.com> Date: Wed, 28 Oct 2020 11:23:11 -0700 Subject: [PATCH] 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 --- logging/examples_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/logging/examples_test.go b/logging/examples_test.go index b9623eea87cd..4ff423ddd966 100644 --- a/logging/examples_test.go +++ b/logging/examples_test.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "net/http" "os" "cloud.google.com/go/logging" @@ -86,6 +87,23 @@ func ExampleClient_Logger() { _ = 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")