-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added optional request and response logging #6
Changes from all commits
f230abf
6aeff66
0133e40
29e8936
b2cddbf
273fe2c
a1983d9
c51e28b
1b1904c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
debug.test | ||
.idea |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,3 +234,36 @@ client.SetUserAgent("your-user-agent-value") | |
|
||
// send API request... | ||
``` | ||
|
||
# Logging | ||
|
||
## Adding a custom logger | ||
|
||
You can add a custom logger to the client that will be used to print outgoing requests and incoming responses. Debug | ||
mode must be set to `true` to enable logging. | ||
|
||
This is an example of how to enable logging and log to a file: | ||
|
||
```go | ||
// Create a logger, which outputs to file. | ||
f, err := os.OpenFile("log.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666) | ||
if err != nil { | ||
log.Fatalf("error opening file: %v", err) | ||
} | ||
defer f.Close() | ||
|
||
fileLogger := &log.Logger{} | ||
fileLogger.SetOutput(f) | ||
|
||
client, err := helix.NewClient(&helix.Options{ | ||
logger: fileLogger, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
debug: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
if err != nil { | ||
log.Fatalf("error opening file: %v", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be |
||
|
||
} | ||
``` | ||
|
||
Should you want to enable debug mode but not want to use a custom logger, stdout will be used as the default log output. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be
// handle error