replace fmt.Fprintf(os.Stderr, ...) with log.Printf()

pull/99/head
ianwoolf 2019-08-06 22:12:26 +08:00 committed by kun
parent 6141bae547
commit 55a9e0a0c5
2 changed files with 6 additions and 7 deletions

View File

@ -83,9 +83,9 @@ func main() {
var handle http.Handler
if proxyHost != "" {
fmt.Fprintf(os.Stderr, "ProxyHost %s\n", proxyHost)
log.Printf("ProxyHost %s\n", proxyHost)
if excludeHost != "" {
fmt.Fprintf(os.Stderr, "ExcludeHost %s\n", excludeHost)
log.Printf("ExcludeHost %s\n", excludeHost)
}
handle = &logger{proxy.NewRouter(proxy.NewServer(new(ops)), &proxy.RouterOptions{
Pattern: excludeHost,
@ -129,7 +129,7 @@ func (l *logger) ServeHTTP(w http.ResponseWriter, r *http.Request) {
start := time.Now()
rl := &responseLogger{code: 200, ResponseWriter: w}
l.h.ServeHTTP(rl, r)
fmt.Fprintf(os.Stderr, "%.3fs %d %s\n", time.Since(start).Seconds(), rl.code, r.URL)
log.Printf("%.3fs %d %s\n", time.Since(start).Seconds(), rl.code, r.URL)
}
// An ops is a proxy.ServerOps implementation.

View File

@ -2,11 +2,10 @@ package proxy
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"path"
"strings"
)
@ -59,11 +58,11 @@ func (rt *Router) Direct(path string) bool {
func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if rt.proxy != nil && rt.Direct(r.URL.Path) {
fmt.Fprintf(os.Stderr, "------ --- %s [direct]\n", r.URL)
log.Printf("------ --- %s [direct]\n", r.URL)
rt.srv.ServeHTTP(w, r)
return
}
fmt.Fprintf(os.Stderr, "------ --- %s [proxy]\n", r.URL)
log.Printf("------ --- %s [proxy]\n", r.URL)
rt.proxy.ServeHTTP(w, r)
return
}