about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tools/nixery/server/logs.go34
-rw-r--r--tools/nixery/server/main.go5
2 files changed, 36 insertions, 3 deletions
diff --git a/tools/nixery/server/logs.go b/tools/nixery/server/logs.go
index 9d1f17aed5cf..dec4a410fb06 100644
--- a/tools/nixery/server/logs.go
+++ b/tools/nixery/server/logs.go
@@ -40,16 +40,46 @@ func isError(e *log.Entry) bool {
 		e.HasCaller()
 }
 
+// logSeverity formats the entry's severity into a format compatible
+// with Stackdriver Logging.
+//
+// The two formats that are being mapped do not have an equivalent set
+// of severities/levels, so the mapping is somewhat arbitrary for a
+// handful of them.
+//
+// https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
+func logSeverity(l log.Level) string {
+	switch l {
+	case log.TraceLevel:
+		return "DEBUG"
+	case log.DebugLevel:
+		return "DEBUG"
+	case log.InfoLevel:
+		return "INFO"
+	case log.WarnLevel:
+		return "WARNING"
+	case log.ErrorLevel:
+		return "ERROR"
+	case log.FatalLevel:
+		return "CRITICAL"
+	case log.PanicLevel:
+		return "EMERGENCY"
+	default:
+		return "DEFAULT"
+	}
+}
+
 func (f stackdriverFormatter) Format(e *log.Entry) ([]byte, error) {
 	msg := e.Data
 	msg["serviceContext"] = &nixeryContext
 	msg["message"] = &e.Message
 	msg["eventTime"] = &e.Time
+	msg["severity"] = logSeverity(e.Level)
 
 	if isError(e) {
 		loc := reportLocation{
-			FilePath: e.Caller.File,
-			LineNumber: e.Caller.Line,
+			FilePath:     e.Caller.File,
+			LineNumber:   e.Caller.Line,
 			FunctionName: e.Caller.Function,
 		}
 		msg["context"] = &loc
diff --git a/tools/nixery/server/main.go b/tools/nixery/server/main.go
index ca1f3c69f2d8..06de6a96a143 100644
--- a/tools/nixery/server/main.go
+++ b/tools/nixery/server/main.go
@@ -247,7 +247,10 @@ func main() {
 		Pop:    pop,
 	}
 
-	log.Printf("Starting Nixery (version %s) on port %s\n", version, cfg.Port)
+	log.WithFields(log.Fields{
+		"version": version,
+		"port":    cfg.Port,
+	}).Info("Starting Nixery")
 
 	// All /v2/ requests belong to the registry handler.
 	http.Handle("/v2/", &registryHandler{