diff --git a/krArc/CMakeLists.txt b/krArc/CMakeLists.txt --- a/krArc/CMakeLists.txt +++ b/krArc/CMakeLists.txt @@ -4,6 +4,7 @@ krarc.cpp krarcbasemanager.cpp krlinecountingprocess.cpp + krdebuglogger.cpp ) add_library(kio_krarc MODULE ${kio_krarc_PART_SRCS}) diff --git a/krArc/krarc.h b/krArc/krarc.h --- a/krArc/krarc.h +++ b/krArc/krarc.h @@ -30,6 +30,7 @@ #include "krarcbasemanager.h" #include "krlinecountingprocess.h" +#include "krdebuglogger.h" class KFileItem; class QByteArray; diff --git a/krArc/krarc.cpp b/krArc/krarc.cpp --- a/krArc/krarc.cpp +++ b/krArc/krarc.cpp @@ -39,73 +39,6 @@ #define MAX_IPC_SIZE (1024*32) #define TRIES_WITH_PASSWORDS 3 -#ifdef QT_DEBUG - -#include - -//! Writes a function name in the krarc debug log, etc. when entering the function and automatically before exiting from it -#define KRFUNC \ - KrDebugLogger functionLogger(__FUNCTION__, __LINE__); - -//! A class to manage some aspects of the writing of messages into the krarc debug log file -class KrDebugLogger -{ -private: - QString function; //! The name of a function which is going to be written about - static int indentation; //! The indentation that is presently used, it represents how many spaces are going to be used - const static int indentationIncrease; //! The quantity of spaces that are going be added to the indentation when increasing it - static const QString logFile; - -public: - //! Prepares some elements before a posterior writing into the krarc debug log file - static void prepareWriting(QFile &file, QTextStream &stream) - { - file.setFileName(logFile); - file.open(QIODevice::WriteOnly | QIODevice::Append); - stream.setDevice(&file); - stream << "Pid:" << (int)getpid(); - // Applies the indentation level to make logs clearer - for (int x = 0; x < indentation; ++x) - stream << " "; - } - - KrDebugLogger(const QString &argFunction, int line) : function(argFunction) - { - QFile file; - QTextStream stream; - prepareWriting(file, stream); - stream << QString("┏"); - stream << function << "(" << line << ")" << endl; - indentation += indentationIncrease; - } - - ~KrDebugLogger() - { - indentation -= indentationIncrease; - QFile file; - QTextStream stream; - prepareWriting(file, stream); - stream << QString("┗"); - stream << function << endl; - } -}; - -int KrDebugLogger::indentation = 1; -const int KrDebugLogger::indentationIncrease = 3; -const QString KrDebugLogger::logFile = "/tmp/krdebug"; - -#define KRDEBUG(X...) do{ \ - QFile file; \ - QTextStream stream; \ - KrDebugLogger::prepareWriting(file, stream); \ - stream << __FUNCTION__ << "(" <<__LINE__<< "): "; \ - stream << X << endl; \ - } while(0); -#else -#define KRFUNC -#define KRDEBUG(X...) qDebug() << X -#endif - using namespace KIO; extern "C" { diff --git a/krArc/krdebuglogger.h b/krArc/krdebuglogger.h new file mode 100644 --- /dev/null +++ b/krArc/krdebuglogger.h @@ -0,0 +1,61 @@ +/*************************************************************************** + krdebuglogger.h + ------------------ + copyright : (C) 2016 by Rafi Yanai & Shie Erlich + email : krusader@users.sf.net + web site : http://krusader.sourceforge.net + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef KRDEBUGLOGGER_H +#define KRDEBUGLOGGER_H + +#include +#include +#include + +#include + +//! A class to manage some aspects of the writing of messages into the krarc debug log file +class KrDebugLogger +{ +private: + QString function; //! The name of a function which is going to be written about + static int indentation; //! The indentation that is presently used, it represents how many spaces are going to be used + const static int indentationIncrease; //! The quantity of spaces that are going be added to the indentation when increasing it + static const QString logFile; //! The name of the log file + +public: + KrDebugLogger(const QString &, int); + ~KrDebugLogger(); + static void prepareWriting(QFile &, QTextStream &); +}; + +#ifdef QT_DEBUG + +//! Writes a function name in the krarc debug log, etc. when entering the function and automatically before exiting from it +#define KRFUNC \ + KrDebugLogger functionLogger(__FUNCTION__, __LINE__); + +#define KRDEBUG(X...) do{ \ + QFile file; \ + QTextStream stream; \ + KrDebugLogger::prepareWriting(file, stream); \ + stream << __FUNCTION__ << "(" <<__LINE__<< "): "; \ + stream << X << endl; \ + } while(0); +#else +#define KRFUNC +#define KRDEBUG(X...) qDebug() << X +#endif + +#endif // KRDEBUGLOGGER_H + diff --git a/krArc/krdebuglogger.cpp b/krArc/krdebuglogger.cpp new file mode 100644 --- /dev/null +++ b/krArc/krdebuglogger.cpp @@ -0,0 +1,56 @@ +/*************************************************************************** + krdebuglogger.cpp + ------------------ + copyright : (C) 2016 by Rafi Yanai & Shie Erlich + email : krusader@users.sf.net + web site : http://krusader.sourceforge.net + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "krdebuglogger.h" + +int KrDebugLogger::indentation = 1; +const int KrDebugLogger::indentationIncrease = 3; +const QString KrDebugLogger::logFile = QDir::tempPath() + "/krdebug"; + +//! This constructor is used inside the KRFUNC macro. For more details: the description of the KRFUNC macro can be seen +KrDebugLogger::KrDebugLogger(const QString &argFunction, int line) : function(argFunction) +{ + QFile file; + QTextStream stream; + prepareWriting(file, stream); + stream << QString("┏"); // Indicates that a function has been started + stream << function << "(" << line << ")" << endl; + indentation += indentationIncrease; +} + +//! For more information: the description of the KRFUNC macro can be seen +KrDebugLogger::~KrDebugLogger() +{ + indentation -= indentationIncrease; + QFile file; + QTextStream stream; + prepareWriting(file, stream); + stream << QString("┗"); // Indicates that a function is going to finish + stream << function << endl; +} + +//! Prepares some elements before a writing into the krarc debug log file +void KrDebugLogger::prepareWriting(QFile &file, QTextStream &stream) +{ + file.setFileName(logFile); + file.open(QIODevice::WriteOnly | QIODevice::Append); + stream.setDevice(&file); + stream << "Pid:" << (int)getpid(); + // Applies the indentation level to make logs clearer + for (int x = 0; x < indentation; ++x) + stream << " "; +}