File indexing completed on 2024-05-19 05:49:11
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 "acpidAnalyzer.h" 0008 0009 AcpidAnalyzer::AcpidAnalyzer(LogMode *logMode) 0010 : FileAnalyzer(logMode) 0011 { 0012 } 0013 0014 LogViewColumns AcpidAnalyzer::initColumns() 0015 { 0016 LogViewColumns columns; 0017 columns.addColumn(LogViewColumn(i18n("Date"), true, false)); 0018 columns.addColumn(LogViewColumn(i18n("Type"), true, true)); 0019 columns.addColumn(LogViewColumn(i18n("Message"), true, false)); 0020 0021 return columns; 0022 } 0023 0024 LogLine *AcpidAnalyzer::parseMessage(const QString &logLine, const LogFile &originalFile) 0025 { 0026 QString line(logLine); 0027 0028 int const dateBegin = line.indexOf(QLatin1String("[")); 0029 int const dateEnd = line.indexOf(QLatin1String("]")); 0030 0031 QString type; 0032 QString message; 0033 QDate date; 0034 QTime time; 0035 0036 // If there is a format problem in the line 0037 if (dateBegin == -1 || dateEnd == -1) { 0038 type = QLatin1String(""); // No type 0039 message = line; 0040 date = QDate::currentDate(); 0041 time = QTime::currentTime(); 0042 } else { 0043 const QString strDate = line.mid(dateBegin + 1, dateEnd - dateBegin - 1); 0044 0045 const QString month = strDate.mid(4, 3); 0046 0047 const QString day = strDate.mid(8, 2); 0048 0049 const QString hour = strDate.mid(11, 2); 0050 const QString min = strDate.mid(14, 2); 0051 const QString sec = strDate.mid(17, 2); 0052 0053 const QString year = strDate.mid(20, 4); 0054 0055 date = QDate(year.toInt(), ParsingHelper::instance()->parseSyslogMonth(month), day.toInt()); 0056 time = QTime(hour.toInt(), min.toInt(), sec.toInt()); 0057 0058 // qCDebug(KSYSTEMLOG) << "Date=" << date.toString(); 0059 // qCDebug(KSYSTEMLOG) << "Time=" << time.toString(); 0060 0061 line.remove(0, dateEnd + 2); 0062 0063 int const endType = line.indexOf(QLatin1String("\"")); 0064 0065 // If the " character does not exist, it means that there is no Type category 0066 if (endType == -1) { 0067 type = QLatin1String(""); // No type 0068 message = line; 0069 } else { 0070 type = line.left(endType - 1); 0071 line.remove(0, endType + 1); 0072 0073 message = line.left(line.length() - 2); 0074 } 0075 } 0076 0077 QStringList list; 0078 0079 list.append(type); 0080 list.append(message); 0081 0082 return new LogLine(mLogLineInternalIdGenerator++, 0083 QDateTime(date, time), 0084 list, 0085 originalFile.url().toLocalFile(), 0086 Globals::instance().informationLogLevel(), 0087 mLogMode); 0088 } 0089 0090 #include "moc_acpidAnalyzer.cpp"