Changeset View
Changeset View
Standalone View
Standalone View
krusader/krdebuglogger.cpp
Context not available. | |||||
21 | 21 | | |||
---|---|---|---|---|---|
22 | #include "krdebuglogger.h" | 22 | #include "krdebuglogger.h" | ||
23 | 23 | | |||
24 | int KrDebugLogger::indentation = 1; | 24 | KrDebugLogger::KrDebugLogger() | ||
25 | const int KrDebugLogger::indentationIncrease = 3; | 25 | { | ||
26 | const QString KrDebugLogger::logFile = QDir::tempPath() + "/krdebug"; | 26 | // Sets the level of detail - verbosity | ||
27 | QByteArray krDebugBrief = qgetenv("KRDEBUG_BRIEF"); | ||||
28 | briefMode = (krDebugBrief == "true" || krDebugBrief == "yes" || krDebugBrief == "on" || krDebugBrief == "1"); | ||||
29 | } | ||||
27 | 30 | | |||
28 | KrDebugLogger::KrDebugLogger(const QString &argFunction, int line) : function(argFunction) | 31 | QString KrDebugLogger::indentationEtc(const QString &argFunction, int line, const QString &fnStartOrEnd) const | ||
29 | { | 32 | { | ||
30 | QFile file; | 33 | QString result = QString(indentation - 1, ' ') % // Applies the indentation level to make logs clearer | ||
31 | QTextStream stream; | 34 | fnStartOrEnd % argFunction; // Uses QStringBuilder to concatenate | ||
32 | prepareWriting(file, stream); | 35 | if (!briefMode) | ||
33 | stream << QString("┏"); // Indicates that a function has been started | 36 | result = QString("Pid:%1 ").arg(getpid()) % | ||
34 | stream << function << "(" << line << ")" << endl; | 37 | result % | ||
35 | indentation += indentationIncrease; | 38 | (line != 0 ? QString("(%1)").arg(line) : ""); | ||
39 | return result; | ||||
36 | } | 40 | } | ||
37 | 41 | | |||
38 | KrDebugLogger::~KrDebugLogger() | 42 | void KrDebugLogger::decreaseIndentation() | ||
39 | { | 43 | { | ||
40 | indentation -= indentationIncrease; | 44 | indentation -= indentationIncrease; | ||
41 | QFile file; | | |||
42 | QTextStream stream; | | |||
43 | prepareWriting(file, stream); | | |||
44 | stream << QString("┗"); // Indicates that a function is going to finish | | |||
45 | stream << function << endl; | | |||
46 | } | 45 | } | ||
47 | 46 | | |||
48 | //! Prepares some elements before a writing into the krarc debug log file | 47 | void KrDebugLogger::increaseIndentation() | ||
49 | void KrDebugLogger::prepareWriting(QFile &file, QTextStream &stream) | 48 | { | ||
49 | indentation += indentationIncrease; | ||||
50 | } | ||||
51 | | ||||
52 | // --------------------------------------------------------------------------------------- | ||||
53 | // Member functions of the KrDebugFnLogger class | ||||
54 | // --------------------------------------------------------------------------------------- | ||||
55 | | ||||
56 | KrDebugFnLogger::KrDebugFnLogger(const QString &argFunction, int line, KrDebugLogger &argKrDebugLogger) : | ||||
57 | function(argFunction), krDebugLogger(argKrDebugLogger) | ||||
58 | { | ||||
59 | // Indicates that a function has been started | ||||
60 | qDebug().nospace().noquote() << krDebugLogger.indentationEtc(function, line, "┏"); | ||||
61 | | ||||
62 | krDebugLogger.increaseIndentation(); | ||||
63 | // This constructor is used inside the KRFUNC macro. For more details: the description of the KRFUNC macro can be seen | ||||
64 | } | ||||
65 | | ||||
66 | KrDebugFnLogger::~KrDebugFnLogger() | ||||
50 | { | 67 | { | ||
51 | file.setFileName(logFile); | 68 | krDebugLogger.decreaseIndentation(); | ||
52 | file.open(QIODevice::WriteOnly | QIODevice::Append); | 69 | // Indicates that a function is going to finish | ||
53 | stream.setDevice(&file); | 70 | qDebug().nospace().noquote() << krDebugLogger.indentationEtc(function, 0, "┗"); | ||
54 | stream << "Pid:" << (int)getpid(); | 71 | // For more information: the description of the KRFUNC macro can be seen | ||
55 | // Applies the indentation level to make logs clearer | | |||
56 | for (int x = 0; x < indentation; ++x) | | |||
57 | stream << " "; | | |||
58 | } | 72 | } | ||
Context not available. |