File indexing completed on 2024-04-14 15:52:16

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 #include "krdebuglogger.h"
0010 #include "compat.h"
0011 
0012 int KrDebugLogger::indentation = 1;
0013 const int KrDebugLogger::indentationIncrease = 3;
0014 const QString KrDebugLogger::logFile = QDir::tempPath() + "/krdebug";
0015 
0016 KrDebugLogger::KrDebugLogger(const QString &argFunction, int line)
0017     : function(argFunction)
0018 {
0019     QFile file;
0020     QTextStream stream;
0021     prepareWriting(file, stream);
0022     stream << QString("┏"); // Indicates that a function has been started
0023     stream << function << "(" << line << ")" << QT_ENDL;
0024     indentation += indentationIncrease;
0025 }
0026 
0027 KrDebugLogger::~KrDebugLogger()
0028 {
0029     indentation -= indentationIncrease;
0030     QFile file;
0031     QTextStream stream;
0032     prepareWriting(file, stream);
0033     stream << QString("┗"); // Indicates that a function is going to finish
0034     stream << function << QT_ENDL;
0035 }
0036 
0037 //! Prepares some elements before a writing into the krarc debug log file
0038 void KrDebugLogger::prepareWriting(QFile &file, QTextStream &stream)
0039 {
0040     file.setFileName(logFile);
0041     file.open(QIODevice::WriteOnly | QIODevice::Append);
0042     stream.setDevice(&file);
0043     stream << "Pid:" << (int)getpid();
0044     // Applies the indentation level to make logs clearer
0045     for (int x = 0; x < indentation; ++x)
0046         stream << " ";
0047 }