aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/http/server.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2010-10-12 12:59:18 -0700
committerRob Pike <r@golang.org>2010-10-12 12:59:18 -0700
commit12da5a90e0e51f8c74792ce52f4ec627ae0b8124 (patch)
tree82cc40492cc1807a71e2ef95674fbf2f9784667a /src/pkg/http/server.go
parentd687ea5588ef04942e3c1a41bdf31f447258f2b0 (diff)
downloadgo-12da5a90e0e51f8c74792ce52f4ec627ae0b8124.tar.xz
log: new interface
New logging interface simplifies and generalizes. 1) Loggers now have only one output. 2) log.Stdout, Stderr, Crash and friends are gone. Logging is now always to standard error by default. 3) log.Panic* replaces log.Crash*. 4) Exiting and panicking are not part of the logger's state; instead the functions Exit* and Panic* simply call Exit or panic after printing. 5) There is now one 'standard logger'. Instead of calling Stderr, use Print etc. There are now triples, by analogy with fmt: Print, Println, Printf What was log.Stderr is now best represented by log.Println, since there are now separate Print and Println functions (and methods). 6) New functions SetOutput, SetFlags, and SetPrefix allow global editing of the standard logger's properties. This is new functionality. For instance, one can call log.SetFlags(log.Lshortfile|log.Ltime|log.Lmicroseconds) to get all logging output to show file name, line number, and time stamp. In short, for most purposes log.Stderr -> log.Println or log.Print log.Stderrf -> log.Printf log.Crash -> log.Panicln or log.Panic log.Crashf -> log.Panicf log.Exit -> log.Exitln or log.Exit log.Exitf -> log.Exitf (no change) This has a slight breakage: since loggers now write only to one output, existing calls to log.New() need to delete the second argument. Also, custom loggers with exit or panic properties will need to be reworked. All package code updated to new interface. The test has been reworked somewhat. The old interface will be removed after the new release. For now, its elements are marked 'deprecated' in their comments. Fixes #1184. R=rsc CC=golang-dev https://golang.org/cl/2419042
Diffstat (limited to 'src/pkg/http/server.go')
-rw-r--r--src/pkg/http/server.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go
index 03653ef87d..44ad8f1df9 100644
--- a/src/pkg/http/server.go
+++ b/src/pkg/http/server.go
@@ -212,11 +212,11 @@ func (w *response) SetHeader(hdr, val string) { w.header[CanonicalHeaderKey(hdr)
// WriteHeader implements the ResponseWriter.WriteHeader method
func (w *response) WriteHeader(code int) {
if w.conn.hijacked {
- log.Stderr("http: response.WriteHeader on hijacked connection")
+ log.Print("http: response.WriteHeader on hijacked connection")
return
}
if w.wroteHeader {
- log.Stderr("http: multiple response.WriteHeader calls")
+ log.Print("http: multiple response.WriteHeader calls")
return
}
w.wroteHeader = true
@@ -248,7 +248,7 @@ func (w *response) WriteHeader(code int) {
// Write implements the ResponseWriter.Write method
func (w *response) Write(data []byte) (n int, err os.Error) {
if w.conn.hijacked {
- log.Stderr("http: response.Write on hijacked connection")
+ log.Print("http: response.Write on hijacked connection")
return 0, ErrHijacked
}
if !w.wroteHeader {
@@ -721,7 +721,7 @@ func ListenAndServe(addr string, handler Handler) os.Error {
//
// func main() {
// http.HandleFunc("/", handler)
-// log.Stdoutf("About to listen on 10443. Go to https://127.0.0.1:10443/")
+// log.Printf("About to listen on 10443. Go to https://127.0.0.1:10443/")
// err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil)
// if err != nil {
// log.Exit(err)