trafficcontrol-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dang...@apache.org
Subject [1/6] incubator-trafficcontrol git commit: add TM2 log.Write
Date Mon, 14 Nov 2016 21:59:11 GMT
Repository: incubator-trafficcontrol
Updated Branches:
  refs/heads/psql-rebase 477fb3a6c -> dceef530c


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/9d119b35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/9d119b35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/9d119b35

Branch: refs/heads/psql-rebase
Commit: 9d119b35ebf4099699992ce22e9619580598b25c
Parents: cd5407b
Author: Robert Butts <robert.o.butts@gmail.com>
Authored: Mon Nov 7 14:50:39 2016 -0700
Committer: Dan Kirkwood <dangogh@gmail.com>
Committed: Mon Nov 14 14:56:10 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/9d119b35/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)
+	}
+}


Mime
View raw message