Changeset View
Changeset View
Standalone View
Standalone View
krusader/krdebuglogger.h
Context not available. | |||||
23 | #define KRDEBUGLOGGER_H | 23 | #define KRDEBUGLOGGER_H | ||
---|---|---|---|---|---|
24 | 24 | | |||
25 | // QtCore | 25 | // QtCore | ||
26 | #include <QFile> | 26 | #include <QDebug> | ||
27 | #include <QDir> | 27 | #include <QDir> | ||
28 | #include <QFile> | ||||
29 | #include <QStringBuilder> | ||||
28 | #include <QTextStream> | 30 | #include <QTextStream> | ||
29 | 31 | | |||
30 | #include <unistd.h> | 32 | #include <unistd.h> | ||
31 | 33 | | |||
32 | //! A class to manage some aspects of the writing of messages into the Krusader debug log file | 34 | //! Manages a system aimed to show debug messages | ||
33 | class KrDebugLogger | 35 | class KrDebugLogger | ||
34 | { | 36 | { | ||
37 | public: | ||||
38 | KrDebugLogger(); | ||||
39 | ~KrDebugLogger() {} | ||||
40 | | ||||
41 | //! Builds a QString that contains the corresponding indentation and other information that has to be written | ||||
42 | /*! | ||||
43 | \param argFunction The name of the function where this method is called. | ||||
44 | \param line The line where this method is called. | ||||
45 | \param fnStartOrEnd In the case of a function: This QString is used to indicate the user if the function is starting or ending. | ||||
46 | \return The corresponding indentation (a group of spaces) and other information that has to be written in the same line. | ||||
47 | */ | ||||
48 | QString indentationEtc(const QString &argFunction, int line = 0, const QString &fnStartOrEnd = "") const; | ||||
49 | //! Decreases the indentation that is going to be used next time | ||||
50 | void decreaseIndentation(); | ||||
51 | //! Increases the indentation that is going to be used next time | ||||
52 | void increaseIndentation(); | ||||
53 | | ||||
35 | private: | 54 | private: | ||
36 | QString function; //! The name of a function which is going to be written about | 55 | int indentation = 1; //! The indentation that is presently used, it represents how many spaces are going to be used to indent | ||
37 | static int indentation; //! The indentation that is presently used, it represents how many spaces are going to be used | 56 | const int indentationIncrease = 4; //! The quantity of spaces that are going be added to the indentation when increasing it | ||
38 | const static int indentationIncrease; //! The quantity of spaces that are going be added to the indentation when increasing it | 57 | | ||
39 | static const QString logFile; //! The name of the log file | 58 | bool briefMode; //! Indicates if debug messages are going to be less detailed, which will be useful e.g. when comparing traces | ||
59 | }; | ||||
60 | | ||||
61 | // --------------------------------------------------------------------------------------- | ||||
40 | 62 | | |||
63 | //! A class that helps to manage: the automatic indentation of debug messages, and their writing when a function starts or ends | ||||
64 | class KrDebugFnLogger | ||||
65 | { | ||||
41 | public: | 66 | public: | ||
42 | //! This constructor is used inside the KRFUNC macro. For more details: the description of the KRFUNC macro can be seen | 67 | KrDebugFnLogger(const QString &argFunction, int line, KrDebugLogger &argKrDebugLogger); | ||
43 | KrDebugLogger(const QString &argFunction, int line); | 68 | ~KrDebugFnLogger(); | ||
44 | //! For more information: the description of the KRFUNC macro can be seen | 69 | | ||
45 | ~KrDebugLogger(); | 70 | private: | ||
46 | static void prepareWriting(QFile &, QTextStream &); | 71 | QString function; //! The name of a function which is going to be written about | ||
72 | KrDebugLogger &krDebugLogger; //! The KrDebugLogger that manages aspects that are common to those objects | ||||
47 | }; | 73 | }; | ||
48 | 74 | | |||
49 | #ifdef QT_DEBUG | 75 | // --------------------------------------------------------------------------------------- | ||
50 | 76 | | |||
51 | //! Writes a function name, etc. in the Krusader debug log when entering the function and automatically before exiting from it | 77 | //! Writes a function name, etc. when entering the function and automatically before exiting from it | ||
52 | #define KRFUNC \ | 78 | #define KRFUNC \ | ||
53 | KrDebugLogger functionLogger(__FUNCTION__, __LINE__); | 79 | KrDebugFnLogger functionLogger(__FUNCTION__, __LINE__, krDebugLogger); | ||
54 | 80 | | |||
55 | #define KRDEBUG(X...) do{ \ | 81 | #define KRDEBUG(X...) \ | ||
56 | QFile file; \ | 82 | qDebug().nospace().noquote() << krDebugLogger.indentationEtc(__FUNCTION__, __LINE__) << ": " << X; | ||
57 | QTextStream stream; \ | | |||
58 | KrDebugLogger::prepareWriting(file, stream); \ | | |||
59 | stream << __FUNCTION__ << "(" <<__LINE__<< "): "; \ | | |||
60 | stream << X << endl; \ | | |||
61 | } while(0); | | |||
62 | #else | | |||
63 | #define KRFUNC | | |||
64 | #define KRDEBUG(X...) qDebug() << X | | |||
65 | #endif | | |||
66 | 83 | | |||
67 | #endif // KRDEBUGLOGGER_H | 84 | #endif // KRDEBUGLOGGER_H | ||
68 | | ||||
Context not available. |