public void ProcessLogLine(LogLine logLine, LogType logType) { if (!(logLine.LineContents is string logString)) { _processingNotificationsCollector.ReportError("Failed to parse log line as string", logLine, nameof(SearchServerPlugin)); return; } var match = _regex.Match(logString); if (!match.Success) { _processingNotificationsCollector.ReportError("Failed to parse log line as SearchServer event", logLine, nameof(SearchServerPlugin)); return; } var parsed = new SearchServerEvent { Class = match.Groups["class"].Value, File = logLine.LogFileInfo.FileName, FilePath = logLine.LogFileInfo.FilePath, LineNumber = logLine.LineNumber, Message = match.Groups["message"].Value, Severity = match.Groups["sev"].Value, Timestamp = TimestampParsers.ParseJavaLogsTimestamp(match.Groups["ts"].Value), Worker = logLine.LogFileInfo.Worker, }; _writer.AddLine(parsed); }
public void ProcessLogLine(LogLine logLine, LogType logType) { var match = logLine.LineContents.CastToStringAndRegexMatch(SharedRegex.JavaLogLineRegex); if (match == null || !match.Success) { _processingNotificationsCollector.ReportError("Failed to parse Vizportal Java event from log line", logLine, nameof(VizportalPlugin)); return; } var @event = new VizportalEvent() { Class = match.GetString("class"), File = logLine.LogFileInfo.FileName, FilePath = logLine.LogFileInfo.FilePath, LineNumber = logLine.LineNumber, Message = match.GetString("message"), RequestId = match.GetString("req"), SessionId = match.GetString("sess"), Severity = match.GetString("sev"), Site = match.GetNullableString("site"), Timestamp = TimestampParsers.ParseJavaLogsTimestamp(match.GetString("ts")), User = match.GetString("user"), Worker = logLine.LogFileInfo.Worker, }; _writer.AddLine(@event); }
public void JavaTimestamps() { foreach (var pair in _javaTimestampTests) { var(input, expectedOutput) = pair; var output = TimestampParsers.ParseJavaLogsTimestamp(input); output.Should().Be(expectedOutput); } }
private FilestoreEvent ParseEvent(LogLine logLine) { var match = logLine.LineContents.CastToStringAndRegexMatch(_regex); if (match == null || !match.Success) { return(null); } return(new FilestoreEvent( logLine: logLine, timestamp: TimestampParsers.ParseJavaLogsTimestamp(match.GetString("ts")), severity: match.GetString("sev"), message: match.GetString("message"), @class: match.GetString("class") )); }
private static BackgrounderJobError ParseErrorMessage(Match lineMatch, LogLine logLine) { if (lineMatch.Groups["sev"].Value != "ERROR" && lineMatch.Groups["sev"].Value != "FATAL") { return(null); } return(new BackgrounderJobError { BackgrounderJobId = long.TryParse(lineMatch.Groups["job_id"].Value, out var jobId) ? jobId : default(long?), Class = lineMatch.Groups["class"].Value, File = logLine.LogFileInfo.FileName, Line = logLine.LineNumber, Message = lineMatch.Groups["message"].Value, Severity = lineMatch.Groups["sev"].Value, Site = lineMatch.Groups["site"].Value, Thread = lineMatch.Groups["thread"].Value, Timestamp = TimestampParsers.ParseJavaLogsTimestamp(lineMatch.Groups["ts"].Value), });
private static (JavaLineMatchResult MatchResult, Match Match) MatchJavaLineAndPopulateCommonFields(object rawJavaLine, Regex regexToUse) { var match = rawJavaLine?.CastToStringAndRegexMatch(regexToUse); if (match == null || !match.Success) { return(JavaLineMatchResult.FailedMatch(), match); } var timestamp = TimestampParsers.ParseJavaLogsTimestamp(match.GetString("ts")); var result = new JavaLineMatchResult(true) { Class = match.GetNullableString("class"), Message = match.GetNullableString("message"), ProcessId = match.GetNullableInt("pid"), Severity = match.GetNullableString("sev"), Thread = match.GetNullableString("thread"), Timestamp = timestamp }; return(result, match); }
private DateTimeOffset ParseTimestamp(LocationInfo locationInfo) { var timestamp = new DateTimeOffset(new DateTime(1900, 1, 1), LocationInfo?.UtcOffset ?? locationInfo.UtcOffset); foreach (var timestampColumn in Survey.TimestampColumns) { var timeText = GetColumnValue(timestampColumn); if (!DateTimeOffset.TryParseExact(timeText, timestampColumn.Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out var value)) { throw new Exception($"Line {LineNumber}: '{timeText}' can't be parsed as a timestamp using the '{timestampColumn.Format}' format."); } if (!TimestampParsers.TryGetValue(timestampColumn.Type, out var timeParser)) { throw new Exception($"{timestampColumn.Name()} Type={timestampColumn.Type} is not a supported time type"); } timestamp = timeParser(timestamp, value); } return(timestamp); }
private void ProcessJavaLine(LogLine logLine) { var match = logLine.LineContents.CastToStringAndRegexMatch(SharedRegex.JavaLogLineRegex); if (match == null || !match.Success) { _processingNotificationsCollector.ReportError("Failed to parse Data Server Java event from log line", logLine, nameof(DataServerPlugin)); return; } var @event = new DataServerEvent( logLine, TimestampParsers.ParseJavaLogsTimestamp(match.GetString("ts")), match.GetString("class"), match.GetNullableString("req"), match.GetNullableString("sess"), match.GetString("sev"), match.GetNullableString("site"), match.GetString("thread"), match.GetNullableString("user"), match.GetString("message")); _writer.AddLine(@event); }
public void JavaTimestampsEdgeCases() { TimestampParsers.ParseJavaLogsTimestamp(null).Should().Be(DateTime.MinValue); TimestampParsers.ParseJavaLogsTimestamp(string.Empty).Should().Be(DateTime.MinValue); TimestampParsers.ParseJavaLogsTimestamp(" ").Should().Be(DateTime.MinValue); }