// SPDX-License-Identifier: GPL-3.0-only /* * Prism Launcher - Minecraft Launcher * Copyright (C) 2025 Rachel Powers <508861+Ryex@users.noreply.github.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, version 3. * * 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, see . * */ #include #include #include #include #include #include #include #include #include "MessageLevel.h" class LogParser { public: struct LogEntry { QString logger; MessageLevel::Enum level; QString levelText; QDateTime timestamp; QString thread; QString message; }; struct Partial { QString data; }; struct PlainText { QString message; }; struct Error { QString errMessage; QXmlStreamReader::Error error; }; using ParsedItem = std::variant; public: LogParser() = default; void appendLine(QAnyStringView data); std::optional parseNext(); QList parseAvailable(); std::optional getError(); /// guess log level from a line of game log static MessageLevel::Enum guessLevel(const QString& line, MessageLevel::Enum level); protected: MessageLevel::Enum parseLogLevel(const QString& level); std::optional parseAttributes(); void setError(); void clearError(); std::optional parseLog4J(); private: QString m_buffer; QString m_partialData; QXmlStreamReader m_parser; std::optional m_error; };