File indexing completed on 2024-03-24 17:26:04
0001 /* 0002 SPDX-FileCopyrightText: 2016 Rafi Yanai <krusader@users.sf.net> 0003 SPDX-FileCopyrightText: 2016 Shie Erlich <krusader@users.sf.net> 0004 SPDX-FileCopyrightText: 2016-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KRDEBUGLOGGER_H 0010 #define KRDEBUGLOGGER_H 0011 0012 // QtCore 0013 #include <QDebug> 0014 #include <QDir> 0015 #include <QFile> 0016 #include <QTextStream> 0017 0018 #include "compat.h" 0019 #include <unistd.h> 0020 0021 //! A class to manage some aspects of the writing of messages into the Krusader debug log file 0022 class KrDebugLogger 0023 { 0024 private: 0025 QString function; //! The name of a function which is going to be written about 0026 static int indentation; //! The indentation that is presently used, it represents how many spaces are going to be used 0027 const static int indentationIncrease; //! The quantity of spaces that are going be added to the indentation when increasing it 0028 static const QString logFile; //! The name of the log file 0029 0030 public: 0031 //! This constructor is used inside the KRFUNC macro. For more details: the description of the KRFUNC macro can be seen 0032 KrDebugLogger(const QString &argFunction, int line); 0033 //! For more information: the description of the KRFUNC macro can be seen 0034 ~KrDebugLogger(); 0035 static void prepareWriting(QFile &, QTextStream &); 0036 }; 0037 0038 #ifdef QT_DEBUG 0039 0040 //! Writes a function name, etc. in the Krusader debug log when entering the function and automatically before exiting from it 0041 #define KRFUNC KrDebugLogger functionLogger(__FUNCTION__, __LINE__); 0042 0043 #define KRDEBUG(...) \ 0044 do { \ 0045 QFile file; \ 0046 QTextStream stream; \ 0047 KrDebugLogger::prepareWriting(file, stream); \ 0048 stream << __FUNCTION__ << "(" << __LINE__ << "): "; \ 0049 stream << __VA_ARGS__ << QT_ENDL; /* Like on https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html */ \ 0050 } while (0); 0051 #else 0052 #define KRFUNC 0053 #define KRDEBUG(...) qDebug() << __VA_ARGS__; 0054 #endif 0055 0056 #endif // KRDEBUGLOGGER_H