Skip to content
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

Use DefaultWriter and DefaultErrorWriter for debug messages #1891

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bytes"
"fmt"
"html/template"
"os"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -54,7 +53,7 @@ func debugPrint(format string, values ...interface{}) {
if !strings.HasSuffix(format, "\n") {
format += "\n"
}
fmt.Fprintf(os.Stderr, "[GIN-debug] "+format, values...)
fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)
}
}

Expand Down Expand Up @@ -98,6 +97,8 @@ at initialization. ie. before any route is registered or the router is listening

func debugPrintError(err error) {
if err != nil {
debugPrint("[ERROR] %v\n", err)
if IsDebugging() {
fmt.Fprintf(DefaultErrorWriter, "[GIN-debug] [ERROR] %v\n", err)
}
}
}
12 changes: 6 additions & 6 deletions debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ func captureOutput(t *testing.T, f func()) string {
if err != nil {
panic(err)
}
stdout := os.Stdout
stderr := os.Stderr
defaultWriter := DefaultWriter
defaultErrorWriter := DefaultErrorWriter
defer func() {
os.Stdout = stdout
os.Stderr = stderr
DefaultWriter = defaultWriter
DefaultErrorWriter = defaultErrorWriter
log.SetOutput(os.Stderr)
}()
os.Stdout = writer
os.Stderr = writer
DefaultWriter = writer
DefaultErrorWriter = writer
log.SetOutput(writer)
out := make(chan string)
wg := new(sync.WaitGroup)
Expand Down