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