xorgAnalyzer.cpp 4.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/***************************************************************************
 *   KSystemLog, a system log viewer tool                                  *
 *   Copyright (C) 2007 by Nicolas Ternisien                               *
 *   nicolas.ternisien@gmail.com                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
 ***************************************************************************/

#include "xorgAnalyzer.h"
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

XorgAnalyzer::XorgAnalyzer(LogMode *logMode)
    : FileAnalyzer(logMode)
    , currentDateTime(QDateTime::currentDateTime())
{
    initializeTypeName();
}

XorgAnalyzer::~XorgAnalyzer()
{
}

LogViewColumns XorgAnalyzer::initColumns()
{
    LogViewColumns columns;

    columns.addColumn(LogViewColumn(i18n("Line"), false, false));
    columns.addColumn(LogViewColumn(i18n("Type"), false, false));
    columns.addColumn(LogViewColumn(i18n("Message"), false, false));

    columns.setGroupByDay(false);
    columns.setGroupByHour(false);

    return columns;
}

LogFileReader *XorgAnalyzer::createLogFileReader(const LogFile &logFile)
{
    return new LocalLogFileReader(logFile);
}

Analyzer::LogFileSortMode XorgAnalyzer::logFileSortMode()
{
    return Analyzer::AscendingSortedLogFile;
}

LogLine *XorgAnalyzer::parseMessage(const QString &logLine, const LogFile &originalFile)
{
    QString string(logLine);

    QString type;

    type = string.left(4);

    LogLevel *logLineType = findTypeName(type);

    // If the type is not empty, the log message has a type, so we can delete it
Laurent Montel's avatar
Laurent Montel committed
70
    if (logLineType != nullptr) {
71
        string.remove(0, 5);
72 73 74 75 76 77 78 79
    } else {
        logLineType = Globals::instance().informationLogLevel();
    }

    QStringList list;
    list.append(logLineType->name());
    list.append(string);

80
    return new LogLine(logLineInternalIdGenerator++, currentDateTime, list, originalFile.url().toLocalFile(),
81 82 83 84 85
                       logLineType, logMode);
}

void XorgAnalyzer::initializeTypeName()
{
86 87
    xorgLevels[QStringLiteral("(--)")] = new LogLevel(
        1001, i18n("Probed"), QStringLiteral(PROBED_LOG_LEVEL_ICON), QColor(246, 206, 30), this);
88

89 90
    xorgLevels[QStringLiteral("(**)")]
        = new LogLevel(1002, i18n("From config file"), QStringLiteral(CONFIG_FILE_LOG_LEVEL_ICON),
91 92
                       QColor(161, 133, 240), this);

93 94
    xorgLevels[QStringLiteral("(==)")]
        = new LogLevel(1003, i18n("Default setting"), QStringLiteral(DEFAULT_SETTING_LOG_LEVEL_ICON),
95 96
                       QColor(169, 189, 165), this);

97 98
    xorgLevels[QStringLiteral("(++)")]
        = new LogLevel(1004, i18n("From command Line"), QStringLiteral(COMMAND_LINE_LOG_LEVEL_ICON),
99 100
                       QColor(179, 181, 214), this);

101 102 103 104
    xorgLevels[QStringLiteral("(!!)")] = Globals::instance().noticeLogLevel();
    xorgLevels[QStringLiteral("(II)")] = Globals::instance().informationLogLevel();
    xorgLevels[QStringLiteral("(WW)")] = Globals::instance().warningLogLevel();
    xorgLevels[QStringLiteral("(EE)")] = Globals::instance().errorLogLevel();
105

106 107
    xorgLevels[QStringLiteral("(NI)")]
        = new LogLevel(1005, i18n("Not implemented"), QStringLiteral(NOT_IMPLEMENTED_LOG_LEVEL_ICON),
108 109
                       QColor(136, 146, 240), this);

110
    xorgLevels[QStringLiteral("(\?\?)")] = Globals::instance().noLogLevel();
111 112 113 114 115 116 117 118 119 120
}

LogLevel *XorgAnalyzer::findTypeName(const QString &type)
{
    QMap<QString, LogLevel *>::iterator it;

    it = xorgLevels.find(type);
    if (it != xorgLevels.end())
        return *it;
    else
Laurent Montel's avatar
Laurent Montel committed
121
        return nullptr;
122
}