From e787f8276d01786eda75e240b77727910106fe0f Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Tue, 12 Oct 2010 16:56:50 -0700 Subject: [PATCH] Effective Go: update examples to use new logging interface. R=adg CC=golang-dev https://golang.org/cl/2468041 --- doc/effective_go.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/effective_go.html b/doc/effective_go.html index fa888b97db..3e1b64dbf6 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -463,7 +463,7 @@ statement, it's common to see one used to set up a local variable.
 if err := file.Chmod(0664); err != nil {
-    log.Stderr(err)
+    log.Print(err)
     return err
 }
 
@@ -815,7 +815,7 @@ which is much clearer than placing it at the end of the function.

-The arguments to the deferred function (which includes the receiver if +The arguments to the deferred function (which include the receiver if the function is a method) are evaluated when the defer executes, not when the call executes. Besides avoiding worries about variables changing values as the function executes, this means @@ -1288,7 +1288,7 @@ func offset(tz string) int { if seconds, ok := timeZone[tz]; ok { return seconds } - log.Stderr("unknown time zone", tz) + log.Println("unknown time zone", tz) return 0 } @@ -1455,13 +1455,13 @@ Within the function Printf, v acts like a variable of []interface{} but if it is passed to another variadic function, it acts like a regular list of arguments. Here is the implementation of the -function log.Stderr we used above. It passes its arguments directly to +function log.Println we used above. It passes its arguments directly to fmt.Sprintln for the actual formatting.

-// Stderr is a helper function for easy logging to stderr. It is analogous to Fprintln(os.Stderr).
-func Stderr(v ...interface{}) {
-    stderr.Output(2, fmt.Sprintln(v))  // Output takes parameters (int, string)
+// Println prints to the standard logger in the manner of fmt.Println.
+func Println(v ...interface{}) {
+    std.Output(2, fmt.Sprintln(v...))  // Output takes parameters (int, string)
 }
 

@@ -2133,7 +2133,7 @@ func NewJob(command string, logger *log.Logger) *Job { or with a composite literal,

-job := &Job{command, log.New(os.Stderr, nil, "Job: ", log.Ldate)}
+job := &Job{command, log.New(os.Stderr, "Job: ", log.Ldate)}
 

If we need to refer to an embedded field directly, the type name of the field, @@ -2675,7 +2675,7 @@ func server(workChan <-chan *Work) { func safelyDo(work *Work) { defer func() { if err := recover(); err != nil { - log.Stderr("work failed:", err) + log.Println("work failed:", err) } }() do(work)