1 /**************************************************************************
2 *   Copyright (C) 2005-2020 by Oleksandr Shneyder                         *
3 *                              <o.shneyder@phoca-gmbh.de>                 *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 *   This program is distributed in the hope that it will be useful,       *
10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 *   GNU General Public License for more details.                          *
13 *                                                                         *
14 *   You should have received a copy of the GNU General Public License     *
15 *   along with this program.  If not, see <https://www.gnu.org/licenses/>. *
16 ***************************************************************************/
17 
18 #ifndef X2GOLOGDEBUG_H
19 #define X2GOLOGDEBUG_H
20 #include <QTextStream>
21 #include <QFile>
22 #include "x2goclientconfig.h"
23 #include "onmainwindow.h"
24 /**
25 	@author Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de>
26 */
27 
28 #define __x2goPrefix      "x2go-"
29 #define __x2goDebugPrefix "DEBUG-"
30 #define __x2goInfoPrefix  "INFO-"
31 #define __x2goWarningPrefix  "WARNING-"
32 #define __x2goErrorPrefix "ERROR-"
33 #define __x2goPostfix     "> "
34 
35 #ifdef LOGFILE
36 class X2goLogDebug: public QTextStream
37 {
38 public:
39     X2goLogDebug();
40     ~X2goLogDebug();
41 
42  private:
43      QFile logFile;
44 };
45 
46 #define __x2goDebug   X2goLogDebug()<<"\n"
47 #define __x2goInfo    X2goLogDebug()<<"\n"
48 #define __x2goWarning X2goLogDebug()<<"\n"
49 #define __x2goError   X2goLogDebug()<<"\n"
50 
51 #else
52 
53 #include <QDebug>
54 
55 #define __x2goDebug   qDebug().nospace()
56 #define __x2goInfo    qDebug().nospace()
57 #define __x2goWarning qWarning().nospace()
58 #define __x2goError   qCritical().nospace()
59 
60 #endif //LOGFILE
61 
62 #define x2goDebugf        __x2goDebug  <<__x2goPrefix<<__x2goDebugPrefix  <<__FILE__<<":"<<__LINE__<<__x2goPostfix
63 #define x2goInfof(NUM)    __x2goInfo   <<__x2goPrefix<<__x2goInfoPrefix   <<NUM                    <<__x2goPostfix
64 #define x2goWarningf(NUM) __x2goWarning<<__x2goPrefix<<__x2goWarningPrefix<<NUM                    <<__x2goPostfix
65 #define x2goErrorf(NUM)   __x2goError  <<__x2goPrefix<<__x2goErrorPrefix  <<NUM                    <<__x2goPostfix
66 
67 #define x2goDebug      if (ONMainWindow::debugging) x2goDebugf
68 
69 #endif //X2GOLOGDEBUG_H
70