Skip to content

Commit

Permalink
Merge pull request PagerDuty#5 from heimweh/f-debug-logging
Browse files Browse the repository at this point in the history
Add basic support for debug logging
  • Loading branch information
heimweh committed Jun 27, 2017
2 parents 0ca7de8 + fa93ae0 commit 7b24055
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pagerduty/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"net/url"

Expand All @@ -25,6 +26,7 @@ type Config struct {
HTTPClient *http.Client
Token string
UserAgent string
Debug bool
}

// Client manages the communication with the PagerDuty API
Expand Down Expand Up @@ -98,6 +100,10 @@ func (c *Client) newRequest(method, url string, body interface{}) (*http.Request
}
}

if c.Config.Debug {
log.Printf("[DEBUG] PagerDuty - Preparing %s request to %s with body: %s", method, url, buf)
}

u := c.baseURL.String() + url

req, err := http.NewRequest(method, u, buf)
Expand All @@ -123,7 +129,9 @@ func (c *Client) newRequestDo(method, url string, options, body, v interface{})
return nil, err
}

url = fmt.Sprintf("%s?%s", url, values.Encode())
if v := values.Encode(); v != "" {
url = fmt.Sprintf("%s?%s", url, v)
}
}

req, err := c.newRequest(method, url, body)
Expand Down

0 comments on commit 7b24055

Please sign in to comment.