File: krdebuglogger.cpp

package info (click to toggle)
krusader 2%3A2.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,448 kB
  • sloc: cpp: 56,112; ansic: 1,187; xml: 811; sh: 23; makefile: 3
file content (62 lines) | stat: -rw-r--r-- 2,088 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
    SPDX-FileCopyrightText: 2016 Rafi Yanai <krusader@users.sf.net>
    SPDX-FileCopyrightText: 2016 Shie Erlich <krusader@users.sf.net>
    SPDX-FileCopyrightText: 2016-2022 Krusader Krew <https://krusader.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "krdebuglogger.h"
#include "compat.h"

#include <QStringBuilder>

KrDebugLogger krDebugLogger;

KrDebugLogger::KrDebugLogger()
{
    // Sets the level of detail/verbosity
    const QByteArray krDebugBrief = qgetenv("KRDEBUG_BRIEF").toLower();
    briefMode = (krDebugBrief == "true" || krDebugBrief == "yes" || krDebugBrief == "on" || krDebugBrief == "1");
}

QString KrDebugLogger::indentedCodePoint(const QString &functionName, int line, const QString &indentationSymbol) const
{
    QString result = QString(indentation, ' ') %  // Applies the indentation level to make logs clearer
                     indentationSymbol % functionName;  // Uses QStringBuilder to concatenate
    if (!briefMode)
        result = QString("Pid:%1 ").arg(getpid()) %
                result %
                (line != 0 ? QString("(%1)").arg(line) : "");
    return result;
}

void KrDebugLogger::decreaseIndentation()
{
    indentation -= indentationIncrease;
}

void KrDebugLogger::increaseIndentation()
{
    indentation += indentationIncrease;
}

// ---------------------------------------------------------------------------------------
// Member functions of the KrDebugFunctionLogger class
// ---------------------------------------------------------------------------------------

KrDebugFunctionLogger::KrDebugFunctionLogger(const QString &functionName, int line) :
    functionName(functionName)
{
    // Shows that a function has been started
    qDebug().nospace().noquote() << krDebugLogger.indentedCodePoint(functionName, line, "┏");

    krDebugLogger.increaseIndentation();
}

KrDebugFunctionLogger::~KrDebugFunctionLogger()
{
    krDebugLogger.decreaseIndentation();
    // Shows that a function is going to finish
    qDebug().nospace().noquote() << krDebugLogger.indentedCodePoint(functionName, 0, "┗");
}