func parseIdeaLogString()

in backend/analyzer/entities/idea.log.go [62:93]


func parseIdeaLogString(logEntryAsString string) (currentEntry analyzer.LogEntry, err error) {
	logParts := analyzer.GetRegexNamedCapturedGroups(`(?s)(?P<Year>\d{4})-(?P<Month>\d{2})-(?P<Day>\d{2})\s+(?P<Hours>\d{2}):(?P<Minutes>\d{2}):(?P<Seconds>\d{2})[.,](?P<MiliSeconds>\d{3})\s+\[\s*(?P<Duration>\d+)\]\s+(?P<Severity>[A-Z]+)\s+\-\s*(?P<Class>.*?)\s*-(?P<Body>.*)`, logEntryAsString)
	if logParts["Year"] == "" {
		return analyzer.LogEntry{
			Text: logEntryAsString,
		}, errors.New("Could not parse idea.log string: " + logEntryAsString)
	}

	currentEntry.Time, _ = time.Parse(time.RFC3339Nano, fmt.Sprintf("%s-%s-%sT%s:%s:%s.%sZ", logParts["Year"], logParts["Month"], logParts["Day"], logParts["Hours"], logParts["Minutes"], logParts["Seconds"], logParts["MiliSeconds"]))
	currentEntry.Severity = strings.TrimSpace(logParts["Severity"])
	currentEntry.Text = logParts["Class"] + " —" + logParts["Body"]

	if logParts["Class"] == "STDERR" {
		currentEntry.Text = strings.TrimPrefix(currentEntry.Text, "STDERR —")
		if !strings.Contains(logParts["Body"], "\t") {
			return analyzer.LogEntry{
				Severity: "EXCPT",
				Time:     currentEntry.Time,
				Text:     currentEntry.Text,
				Visible:  true,
			}, nil
		}
		return analyzer.LogEntry{
			Severity: "PARSE_ERROR",
			Time:     currentEntry.Time,
			Text:     currentEntry.Text,
			Visible:  true,
		}, errors.New("found STDERR in the entry body")
	}

	return currentEntry, err
}