about summary refs log tree commit diff
path: root/tools/nixery/server/layers/grouping.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-10-06T02·18+0100
committerVincent Ambo <github@tazj.in>2019-10-06T22·05+0100
commit6f148f789f43bf753b345b039d01d8a429f194e9 (patch)
tree87569dd6d0d351822c926c250a20ed99e1f4452c /tools/nixery/server/layers/grouping.go
parentf77c93b6aeb3e847fe00099ea5c52dc98cf74b4d (diff)
refactor(server): Convert existing log entries to structured format
This rewrites all existing log statements into the structured logrus
format. For consistency, all errors are always logged separately from
the primary message in a field called `error`.

Only the "info", "error" and "warn" severities are used.
Diffstat (limited to 'tools/nixery/server/layers/grouping.go')
-rw-r--r--tools/nixery/server/layers/grouping.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/tools/nixery/server/layers/grouping.go b/tools/nixery/server/layers/grouping.go
index 95198c90d4b3..1fbbf33db3d7 100644
--- a/tools/nixery/server/layers/grouping.go
+++ b/tools/nixery/server/layers/grouping.go
@@ -172,8 +172,14 @@ func (c *closure) ID() int64 {
 
 var nixRegexp = regexp.MustCompile(`^/nix/store/[a-z0-9]+-`)
 
+// PackageFromPath returns the name of a Nix package based on its
+// output store path.
+func PackageFromPath(path string) string {
+	return nixRegexp.ReplaceAllString(path, "")
+}
+
 func (c *closure) DOTID() string {
-	return nixRegexp.ReplaceAllString(c.Path, "")
+	return PackageFromPath(c.Path)
 }
 
 // bigOrPopular checks whether this closure should be considered for
@@ -321,7 +327,10 @@ func dominate(budget int, graph *simple.DirectedGraph) []Layer {
 	})
 
 	if len(layers) > budget {
-		log.Printf("Ideal image has %v layers, but budget is %v\n", len(layers), budget)
+		log.WithFields(log.Fields{
+			"layers": len(layers),
+			"budget": budget,
+		}).Info("ideal image exceeds layer budget")
 	}
 
 	for len(layers) > budget {