Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Allow the Request passed in to Client.Logger() to be nil
Browse files Browse the repository at this point in the history
  • Loading branch information
justinruggles committed Sep 27, 2018
1 parent 7e27096 commit 2372771
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions grouplogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func (gl *GroupLogger) Close() {
// If LogOuterEntry is not called, nothing from this group will appear in
// the outer log.
func (gl *GroupLogger) CloseWith(stats *logging.HTTPRequest) {
stats.Request = gl.Req
if gl.Req != nil {
stats.Request = gl.Req
}
entry := logging.Entry{
Trace: gl.GroupID,
Severity: gl.getMaxSeverity(),
Expand Down Expand Up @@ -266,8 +268,10 @@ func (gl *GroupLogger) getMaxSeverity() logging.Severity {
// Otherwise, a pseudorandom UUID is used.
func getGroupID(r *http.Request) string {
// If the trace header exists, use the trace.
if id := r.Header.Get("X-Cloud-Trace-Context"); id != "" {
return id
if r != nil {
if id := r.Header.Get("X-Cloud-Trace-Context"); id != "" {
return id
}
}
// Otherwise, generate a random group ID.
return uuid.New().String()
Expand Down

0 comments on commit 2372771

Please sign in to comment.