8784: Add keep-web directory listings via (*arvados.Collection)FileSystem().
[arvados.git] / sdk / go / httpserver / log.go
index 7bee88742c01940017882c987a61ed092eacc12d..cdfc595e67fe6022b151e9624f565cb13f23a1a8 100644 (file)
@@ -1,20 +1,21 @@
 package httpserver
 
 import (
+       "fmt"
        "log"
-       "strings"
 )
 
-var escaper = strings.NewReplacer("\"", "\\\"", "\\", "\\\\", "\n", "\\n")
-
 // Log calls log.Println but first transforms strings so they are
 // safer to write in logs (e.g., 'foo"bar' becomes
-// '"foo\"bar"'). Non-string args are left alone.
+// '"foo\"bar"'). Arguments that aren't strings and don't have a
+// (String() string) method are left alone.
 func Log(args ...interface{}) {
        newargs := make([]interface{}, len(args))
        for i, arg := range args {
                if s, ok := arg.(string); ok {
-                       newargs[i] = "\"" + escaper.Replace(s) + "\""
+                       newargs[i] = fmt.Sprintf("%+q", s)
+               } else if s, ok := arg.(fmt.Stringer); ok {
+                       newargs[i] = fmt.Sprintf("%+q", s.String())
                } else {
                        newargs[i] = arg
                }