File indexing completed on 2024-05-19 05:49:18
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 "xsessionAnalyzer.h" 0008 0009 XSessionAnalyzer::XSessionAnalyzer(LogMode *logMode) 0010 : FileAnalyzer(logMode) 0011 , mCurrentDateTime(QDateTime::currentDateTime()) 0012 { 0013 } 0014 0015 LogViewColumns XSessionAnalyzer::initColumns() 0016 { 0017 LogViewColumns columns; 0018 0019 columns.addColumn(LogViewColumn(i18n("Line"), true, false)); 0020 columns.addColumn(LogViewColumn(i18n("Program"), true, false)); 0021 columns.addColumn(LogViewColumn(i18n("Message"), true, false)); 0022 0023 columns.setGroupByDay(false); 0024 columns.setGroupByHour(false); 0025 0026 return columns; 0027 } 0028 0029 Analyzer::LogFileSortMode XSessionAnalyzer::logFileSortMode() 0030 { 0031 auto *configuration = mLogMode->logModeConfiguration<XSessionConfiguration *>(); 0032 if (configuration->isIgnoreXorgErrors()) { 0033 return Analyzer::FilteredLogFile; 0034 } else { 0035 return Analyzer::AscendingSortedLogFile; 0036 } 0037 } 0038 0039 LogLine *XSessionAnalyzer::parseMessage(const QString &logLine, const LogFile &originalFile) 0040 { 0041 const int classPrototypePosition = logLine.indexOf(QLatin1String("::")); 0042 int programPos = logLine.indexOf(QLatin1Char(':')); 0043 0044 // If the first found : is the begin of a :: (example: QFile::at:) then we move to the next : 0045 if (classPrototypePosition != -1 && programPos == classPrototypePosition) { 0046 programPos = logLine.indexOf(QLatin1Char(':'), classPrototypePosition + 2); 0047 } 0048 0049 QString program; 0050 QString message; 0051 if (programPos == -1) { 0052 program = QLatin1String(""); 0053 message = logLine.simplified(); 0054 } else { 0055 program = logLine.left(programPos); 0056 message = logLine.right(logLine.length() - programPos - 1); 0057 } 0058 0059 message = message.simplified(); 0060 0061 // Do not add this line if this is a X error that the user wants to ignore 0062 if (isXorgError(program)) { 0063 return nullptr; 0064 } 0065 0066 // Find the right log level 0067 LogLevel *logLevel; 0068 if (hasErrorKeywords(message)) { 0069 logLevel = Globals::instance().errorLogLevel(); 0070 } else if (hasWarningKeywords(message)) { 0071 logLevel = Globals::instance().warningLogLevel(); 0072 } else { 0073 logLevel = Globals::instance().informationLogLevel(); 0074 } 0075 0076 return new LogLine(mLogLineInternalIdGenerator++, 0077 mCurrentDateTime, 0078 QStringList() << program << message, 0079 originalFile.url().toLocalFile(), 0080 logLevel, 0081 mLogMode); 0082 } 0083 0084 bool XSessionAnalyzer::isXorgError(const QString &program) 0085 { 0086 auto *configuration = mLogMode->logModeConfiguration<XSessionConfiguration *>(); 0087 if (configuration->isIgnoreXorgErrors() && configuration->xorgErrorKeywords().contains(program)) { 0088 return true; 0089 } 0090 0091 return false; 0092 } 0093 0094 bool XSessionAnalyzer::hasWarningKeywords(const QString &message) 0095 { 0096 auto *configuration = mLogMode->logModeConfiguration<XSessionConfiguration *>(); 0097 return hasKeywords(message, configuration->warningKeywords()); 0098 } 0099 0100 bool XSessionAnalyzer::hasErrorKeywords(const QString &message) 0101 { 0102 auto *configuration = mLogMode->logModeConfiguration<XSessionConfiguration *>(); 0103 return hasKeywords(message, configuration->errorKeywords()); 0104 } 0105 0106 bool XSessionAnalyzer::hasKeywords(const QString &message, const QStringList &keywords) 0107 { 0108 for (const QString &keyword : keywords) { 0109 if (message.contains(keyword, Qt::CaseInsensitive)) { 0110 return true; 0111 } 0112 } 0113 0114 return false; 0115 } 0116 0117 #include "moc_xsessionAnalyzer.cpp"