00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #ifndef __LOG_H_
00024 #define __LOG_H_
00025 
00026 #define gLog Log::instance
00027 
00028 #include "global.h"
00029 #include <QMutex>
00030 #include <QObject>
00031 
00035 class MAIN_EXPORT Log : public QObject
00036 {
00037         Q_OBJECT;
00038 
00039         public:
00043                 static Log                      instance;
00044 
00045                 Log();
00046 
00047                 bool                            areTimestampsEnabled() const { return timestamps; }
00048 
00049                 const QString&          content() const { return logContent; }
00050 
00056                 void                            logPrintf(const char* str, ...);
00057 
00063                 void                            logUnformattedPrintf(const char* str, ...);
00064 
00065                 bool                            isPrintingToStdout() const { return printToStdout; }
00066 
00067                 void                            setPrintingToStdout(bool b) { printToStdout = b; }
00068                 void                            setTimestampsEnabled(bool b) { timestamps = b; }
00069 
00073                 Log&                            operator<<(const QString& string);
00074 
00075         public slots:
00082                 void    addEntry(const QString& string);
00083 
00089                 void    addUnformattedEntry(const QString& string);
00090 
00094                 void    clearContent() { logContent.clear(); }
00095 
00096         signals:
00102                 void    newEntry(const QString& entry);
00103 
00104         protected:
00108                 QString         logContent;
00109                 QMutex          thisMutex;
00110 
00111                 int                     doLogPrintf(char* output, unsigned outputSize, const char* str, va_list argList);
00112 
00118                 bool            printToStdout;
00119 
00123                 bool            timestamps;
00124 
00125 
00126 };
00127 
00128 #endif