Esempio n. 1
0
        public IList <LogEntry> ParseLinesFromLogsScan(IReadOnlyList <string> lines, DateTime dayStamp)
        {
            List <LogEntry> result        = new List <LogEntry>(lines.Count);
            DateTime?       previousStamp = null;

            foreach (var line in lines)
            {
                if (IsLoggingStartedLine(line))
                {
                    continue;
                }
                // maybe just empty line (eg. happens on examining signs)
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                TimeSpan?parsedTime   = null;
                DateTime?currentStamp = null;
                try
                {
                    parsedTime = ParsingHelper.GetTimestampFromLogLine(line);
                }
                catch (Exception exception)
                {
                    logger.Log(LogLevel.Warn, "Found log line with unparseable timestamp, line may be ignored.", this, exception);
                }

                string source  = ParsingHelper.TryParseSourceFromLogLine(line);
                string content = ParsingHelper.TryParseContentFromLogLine(line);
                if (parsedTime.HasValue)
                {
                    currentStamp = new DateTime(dayStamp.Year,
                                                dayStamp.Month,
                                                dayStamp.Day,
                                                parsedTime.Value.Hours,
                                                parsedTime.Value.Minutes,
                                                parsedTime.Value.Seconds);
                }
                else if (previousStamp.HasValue)
                {
                    currentStamp = previousStamp.Value;
                }

                if (currentStamp.HasValue)
                {
                    previousStamp = currentStamp;

                    LogEntry entry = new LogEntry(currentStamp.Value, source, content);
                    result.Add(entry);
                }
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Parses lines with expectation, that they all come from single day indicated by originDate.
        /// In other words, the first line MUST be the first entry on a given day.
        /// </summary>
        /// <returns></returns>
        public IList <LogEntry> ParseLinesForDay(IReadOnlyList <string> lines, DateTime originDate,
                                                 LogFileInfo logFileInfo)
        {
            AssertOriginDate(originDate);

            List <LogEntry> result           = new List <LogEntry>(lines.Count);
            TimeSpan        currentLineStamp = TimeSpan.Zero;

            foreach (var line in lines)
            {
                // handle special types of lines
                if (IsLoggingStartedLine(line))
                {
                    // skip, is of no concern at this point
                    continue;
                }

                // handle timestamp
                var lineStamp = ParsingHelper.TryParseTimestampFromLogLine(line);
                if (lineStamp == TimeSpan.MinValue)
                {
                    // maybe just empty line (eg. happens on examining signs)
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    // bad timestamp may indicate corrupted file, special unforseen case
                    // or log file from when "log timestamps" was disabled in game.
                    HandleUnparseableTimestamp(logFileInfo, line, result);
                    continue;
                }

                if (lineStamp < currentLineStamp)
                {
                    LogTimestampDiscrepancy(logFileInfo, result, line);
                }
                else
                {
                    currentLineStamp = lineStamp;
                }

                string source  = ParsingHelper.TryParseSourceFromLogLine(line);
                string content = ParsingHelper.TryParseContentFromLogLine(line);

                LogEntry entry = new LogEntry(originDate + currentLineStamp, source, content, logFileInfo.PmRecipientNormalized);

                result.Add(entry);
            }

            return(result);
        }
Esempio n. 3
0
 private bool IsLoggingStartedLine(string line)
 {
     return(ParsingHelper.IsLoggingStartedLine(line));
 }