File indexing completed on 2024-05-19 05:49:17
0001 /* 0002 SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "sambaAnalyzer.h" 0008 0009 SambaAnalyzer::SambaAnalyzer(LogMode *logMode) 0010 : FileAnalyzer(logMode) 0011 { 0012 mCurrentLogLine = nullptr; 0013 } 0014 0015 LogViewColumns SambaAnalyzer::initColumns() 0016 { 0017 LogViewColumns columns; 0018 0019 columns.addColumn(LogViewColumn(i18n("Date"), true, false)); 0020 columns.addColumn(LogViewColumn(i18n("Source File"), true, true)); 0021 columns.addColumn(LogViewColumn(i18n("Function"), true, true)); 0022 columns.addColumn(LogViewColumn(i18n("Line"), true, true)); 0023 columns.addColumn(LogViewColumn(i18n("Message"), true, false)); 0024 0025 return columns; 0026 } 0027 0028 LogFileReader *SambaAnalyzer::createLogFileReader(const LogFile &logFile) 0029 { 0030 return new LocalLogFileReader(logFile); 0031 } 0032 0033 Analyzer::LogFileSortMode SambaAnalyzer::logFileSortMode() 0034 { 0035 return Analyzer::AscendingSortedLogFile; 0036 } 0037 0038 LogLine *SambaAnalyzer::parseMessage(const QString &logLine, const LogFile &originalLogFile) 0039 { 0040 QString line(logLine); 0041 0042 // The Date 0043 const int dateBegin = line.indexOf(QLatin1String("[")); 0044 const int dateEnd = line.indexOf(QLatin1String("]")); 0045 0046 if (dateBegin != -1) { 0047 const QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1); 0048 0049 const QString year = strDate.mid(0, 4); 0050 const QString month = strDate.mid(5, 2); 0051 const QString day = strDate.mid(8, 2); 0052 0053 const QString hour = strDate.mid(11, 2); 0054 const QString min = strDate.mid(14, 2); 0055 const QString sec = strDate.mid(17, 2); 0056 0057 const QDate date = QDate(year.toInt(), month.toInt(), day.toInt()); 0058 const QTime time = QTime(hour.toInt(), min.toInt(), sec.toInt()); 0059 0060 line.remove(0, dateEnd + 2); 0061 0062 // The source file 0063 int doubleDot; 0064 doubleDot = line.indexOf(QLatin1Char(':')); 0065 QString const file = line.left(doubleDot); 0066 line.remove(0, doubleDot + 1); 0067 0068 // The function 0069 int bracket = line.indexOf(QLatin1Char('(')); 0070 const QString function = line.left(bracket); 0071 line.remove(0, bracket + 1); 0072 0073 // The line number 0074 bracket = line.indexOf(QLatin1Char(')')); 0075 const QString lineNumber = line.left(bracket); 0076 0077 // Remove the first return character and the two useless space of the first message line 0078 line.remove(0, bracket + 4); 0079 0080 QStringList list; 0081 list.append(file); 0082 list.append(function); 0083 list.append(lineNumber); 0084 0085 qCDebug(KSYSTEMLOG) << "Creating new line "; 0086 0087 LogLine *returnedLogLine = mCurrentLogLine; 0088 0089 mCurrentLogLine = new LogLine(mLogLineInternalIdGenerator++, 0090 QDateTime(date, time), 0091 list, 0092 originalLogFile.url().toLocalFile(), 0093 Globals::instance().informationLogLevel(), 0094 mLogMode); 0095 0096 return returnedLogLine; 0097 } 0098 0099 if (line.indexOf(QLatin1String(" ")) != -1) { 0100 if (mCurrentLogLine) { 0101 QStringList list = mCurrentLogLine->logItems(); 0102 0103 // A line has already been added 0104 if (list.count() == 4) { 0105 const QString currentMessage = list.takeLast(); 0106 list.append(currentMessage + QLatin1String("\n") + line.simplified()); 0107 } 0108 // First time we add a line for the current Log line 0109 else { 0110 list.append(line.simplified()); 0111 } 0112 0113 mCurrentLogLine->setLogItems(list); 0114 } 0115 } 0116 0117 return nullptr; 0118 } 0119 0120 #include "moc_sambaAnalyzer.cpp"