Skip to content

Commit

Permalink
docs(logging): add example for logging the HTTPRequest type (#3097)
Browse files Browse the repository at this point in the history
* docs(logging): add example for logging the HTTPRequest type

* ci(logging): go fmt examples_test.go
  • Loading branch information
freelerobot authored Oct 28, 2020
1 parent 47f473c commit 9250337
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions logging/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"

"cloud.google.com/go/logging"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 9250337

Please sign in to comment.