Browse Source

supports rfc3164

also, align hostname to docs -> host
boyska 5 years ago
parent
commit
46a031695c
2 changed files with 19 additions and 10 deletions
  1. 1 1
      formatter/format.go
  2. 18 9
      hub.go

+ 1 - 1
formatter/format.go

@@ -56,7 +56,7 @@ func init() {
 		},
 	}
 	syslogTmpl = template.Must(template.New("syslog").Funcs(tmplFuncs).Parse(
-		"{{color \"yellow\" (rfc822 (index . \"time\")) }} {{index . \"hostname\"}} " +
+		"{{color \"yellow\" (rfc822 (index . \"time\")) }} {{index . \"host\"}} " +
 			"{{index . \"prog\" | autoColor}}" +
 			"{{ if (ne (index . \"proc_id\") \"-\")}}[{{index . \"proc_id\"}}]{{end}}: " +
 			"{{ sevName (index . \"sev\") }} " +

+ 18 - 9
hub.go

@@ -126,15 +126,24 @@ func (h *Hub) register(cl Client) {
 // logEntryToMessage converts messages received from writers to the format we promise to readers
 func logEntryToMessage(orig format.LogParts) Message {
 	m := Message{}
-	// it currently only supports RFC5424. TODO: support RFC3164
-	m["prog"] = orig["app_name"]
-	m["client"] = orig["client"]
-	m["hostname"] = orig["hostname"]
-	m["proc_id"] = orig["proc_id"]
-	m["msg"] = orig["message"]
-	m["facility"] = orig["facility"]
-	m["time"] = orig["timestamp"]
-	m["sev"] = orig["severity"]
+	if orig["version"] == 1 { // RFC5424
+		m["prog"] = orig["app_name"]
+		m["client"] = orig["client"]
+		m["host"] = orig["hostname"]
+		m["proc_id"] = orig["proc_id"]
+		m["msg"] = orig["message"]
+		m["facility"] = orig["facility"]
+		m["time"] = orig["timestamp"]
+		m["sev"] = orig["severity"]
+	} else { //RFC3164
+		m["prog"] = orig["tag"]
+		m["client"] = orig["client"]
+		m["host"] = orig["hostname"]
+		m["msg"] = orig["content"]
+		m["sev"] = orig["severity"]
+		m["time"] = orig["timestamp"]
+		m["proc_id"] = "-"
+	}
 	return m
 }