Browse Source

Truncate the panic log field when it exceeds the ELK maximum

Rod Hynes 7 years ago
parent
commit
d74692910c
1 changed files with 8 additions and 0 deletions
  1. 8 0
      Server/main.go

+ 8 - 0
Server/main.go

@@ -287,6 +287,14 @@ func panicHandler(output string) {
 		logEvent["build_rev"] = common.GetBuildInfo().BuildRev
 		logEvent["timestamp"] = time.Now().Format(time.RFC3339)
 		logEvent["event_name"] = "server_panic"
+
+		// ELK has a maximum field length of 32766 UTF8 bytes. Over that length, the
+		// log won't be delivered. Truncate the panic field, as it may be much longer.
+		maxLen := 32766
+		if len(output) > maxLen {
+			output = output[:maxLen]
+		}
+
 		logEvent["panic"] = output
 
 		// Logs are written to the configured file name. If no name is specified, logs are written to stderr