Fix TO Golang access.log text

Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/4a3f7db7
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/4a3f7db7
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/4a3f7db7

Branch: refs/heads/master
Commit: 4a3f7db7d3ffa7d3a5dd97da95d1caa3b6efb56e
Parents: 8b0ac5f
Author: Robert Butts <robert.o.bu...@gmail.com>
Authored: Mon Jul 24 21:53:33 2017 -0600
Committer: Dewayne Richardson <dewr...@apache.org>
Committed: Thu Aug 10 09:46:03 2017 -0600

----------------------------------------------------------------------
 traffic_monitor_golang/common/log/log.go     | 5 +++++
 traffic_ops/traffic_ops_golang/perlconfig.go | 4 ++--
 traffic_ops/traffic_ops_golang/wrappers.go   | 7 +++++--
 3 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4a3f7db7/traffic_monitor_golang/common/log/log.go
----------------------------------------------------------------------
diff --git a/traffic_monitor_golang/common/log/log.go 
b/traffic_monitor_golang/common/log/log.go
index dd63892..a5204b5 100644
--- a/traffic_monitor_golang/common/log/log.go
+++ b/traffic_monitor_golang/common/log/log.go
@@ -134,6 +134,11 @@ func Eventf(t time.Time, format string, v ...interface{}) {
        Event.Printf("%.3f %s", 
float64(t.Unix())+(float64(t.Nanosecond())/1e9), fmt.Sprintf(format, v...))
 }
 
+// EventfRaw writes to the event log with no prefix.
+func EventfRaw(format string, v ...interface{}) {
+       Event.Printf(format, v...)
+}
+
 // Close calls `Close()` on the given Closer, and logs any error. On error, 
the context is logged, followed by a colon, the error message, and a newline. 
This is primarily designed to be used in `defer`, for example, `defer 
log.Close(resp.Body, "readData fetching /foo/bar")`.
 func Close(c io.Closer, context string) {
        err := c.Close()

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4a3f7db7/traffic_ops/traffic_ops_golang/perlconfig.go
----------------------------------------------------------------------
diff --git a/traffic_ops/traffic_ops_golang/perlconfig.go 
b/traffic_ops/traffic_ops_golang/perlconfig.go
index c7abf64..a3013dc 100644
--- a/traffic_ops/traffic_ops_golang/perlconfig.go
+++ b/traffic_ops/traffic_ops_golang/perlconfig.go
@@ -65,10 +65,10 @@ func getPerlConfigsFromStrs(cdnConfBytes string, 
dbConfBytes string) (Config, er
                cfg.DBServer += ":" + dbconf.Port
        }
 
-       cfg.LogLocationInfo = OldAccessLogPath
+       cfg.LogLocationInfo = NewLogPath
        cfg.LogLocationError = NewLogPath
        cfg.LogLocationWarning = NewLogPath
-       cfg.LogLocationEvent = NewLogPath
+       cfg.LogLocationEvent = OldAccessLogPath
        cfg.LogLocationDebug = log.LogLocationNull
 
        return cfg, nil

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/4a3f7db7/traffic_ops/traffic_ops_golang/wrappers.go
----------------------------------------------------------------------
diff --git a/traffic_ops/traffic_ops_golang/wrappers.go 
b/traffic_ops/traffic_ops_golang/wrappers.go
index 64afeff..b20cd53 100644
--- a/traffic_ops/traffic_ops_golang/wrappers.go
+++ b/traffic_ops/traffic_ops_golang/wrappers.go
@@ -49,7 +49,7 @@ func wrapAuth(h RegexHandlerFunc, noAuth bool, secret string, 
privLevelStmt *sql
                w = iw
                username := "-"
                defer func() {
-                       log.Infof(`%s - %s [%s] "%v %v HTTP/1.1" %v 0 0 
"%v"\n`, r.RemoteAddr, username, time.Now().Format(AccessLogTimeFormat), 
r.Method, r.URL.Path, iw.code, time.Now().Sub(start)/time.Millisecond, 
iw.byteCount, r.UserAgent())
+                       log.EventfRaw(`%s - %s [%s] "%v %v HTTP/1.1" %v %v %v 
"%v"`, r.RemoteAddr, username, time.Now().Format(AccessLogTimeFormat), 
r.Method, r.URL.Path, iw.code, int(time.Now().Sub(start)/time.Millisecond), 
iw.byteCount, r.UserAgent())
                }()
 
                handleUnauthorized := func(reason string) {
@@ -96,7 +96,7 @@ func wrapLogTime(h RegexHandlerFunc) RegexHandlerFunc {
                iw := &Interceptor{w: w}
                defer func() {
                        user := "-" // TODO fix
-                       log.Infof(`%s - %s [%s] "%v %v HTTP/1.1" %v 0 0 
"%v"\n`, r.RemoteAddr, user, time.Now().Format(AccessLogTimeFormat), r.Method, 
r.URL.Path, iw.code, time.Now().Sub(start)/time.Millisecond, iw.byteCount, 
r.UserAgent())
+                       log.EventfRaw(`%s - %s [%s] "%v %v HTTP/1.1" %v 0 0 
"%v"\n`, r.RemoteAddr, user, time.Now().Format(AccessLogTimeFormat), r.Method, 
r.URL.Path, iw.code, time.Now().Sub(start)/time.Millisecond, iw.byteCount, 
r.UserAgent())
                }()
                h(iw, r, p)
        }
@@ -116,6 +116,9 @@ func (i *Interceptor) WriteHeader(rc int) {
 func (i *Interceptor) Write(b []byte) (int, error) {
        wi, werr := i.w.Write(b)
        i.byteCount += wi
+       if i.code == 0 {
+               i.code = 200
+       }
        return wi, werr
 }
 

Reply via email to