You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2016/11/14 17:09:10 UTC

[4/5] incubator-trafficcontrol git commit: add TM2 log.Write

add TM2 log.Write


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

Branch: refs/heads/master
Commit: 93d1372e485eda0b5d5c80149c47e9f2c242a0db
Parents: f22f002
Author: Robert Butts <ro...@gmail.com>
Authored: Mon Nov 7 14:50:39 2016 -0700
Committer: Dave Neuman <ne...@apache.org>
Committed: Mon Nov 14 10:08:17 2016 -0700

----------------------------------------------------------------------
 traffic_monitor/experimental/common/log/log.go | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/93d1372e/traffic_monitor/experimental/common/log/log.go
----------------------------------------------------------------------
diff --git a/traffic_monitor/experimental/common/log/log.go b/traffic_monitor/experimental/common/log/log.go
index 884d4c3..0fd33c9 100644
--- a/traffic_monitor/experimental/common/log/log.go
+++ b/traffic_monitor/experimental/common/log/log.go
@@ -85,3 +85,20 @@ func Closef(c io.Closer, contextFormat string, v ...interface{}) {
 		Errorf(": %v", err)
 	}
 }
+
+// Write calls `Write()` on the given Writer, and logs any error. On error, the context is logged, followed by a colon, the error message, and a newline.
+func Write(w io.Writer, b []byte, context string) {
+	_, err := w.Write(b)
+	if err != nil {
+		Errorf("%v: %v", context, err)
+	}
+}
+
+// Writef acts like Write, with a given format string and values, followed by a colon, the error message, and a newline. The given values are not coerced, concatenated, or printed unless an error occurs, so this is more efficient than `Write()`.
+func Writef(w io.Writer, b []byte, contextFormat string, v ...interface{}) {
+	_, err := w.Write(b)
+	if err != nil {
+		Errorf(contextFormat, v...)
+		Errorf(": %v", err)
+	}
+}