00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ASPECT_LOG_H
00013 #define ASPECT_LOG_H
00014
00015 #include <QtCore>
00016
00017 #define LOG(a, b ...) do { if (a <= 2) { qDebug(b); Log::log(b); } } while (false)
00018 #define DO_LOG(a) (a <= 2)
00019 #define LOG_MCU(a ...) do { Log::mcu(a, QTime::currentTime()); } while (false)
00020
00021
00022 #define LQS(a) (a).toUtf8().constData()
00023
00024
00025 class Log
00026 {
00027 public:
00028 static void mcu(const QString &qsText, const QTime &oTime);
00029 static void log(const char *szFmt, ...)
00030 #if 0 // don't; gives double compiler warnings as LOG() calls qDebug also
00031 #if defined(Q_CC_GNU) && !defined(__INSURE__)
00032 __attribute__ ((format (printf, 1, 2)))
00033 #endif
00034 #endif
00035 ;
00036
00037 static void startup();
00038 static void shutdown();
00039
00040 static void logConnect(QObject *pObj, const char *szSlot);
00041 static void mcuConnect(QObject *pObj, const char *szSlot);
00042 };
00043
00044
00045 class LogImpl: public QObject
00046 {
00047 Q_OBJECT
00048
00049 public:
00050 LogImpl(const QString &qsType);
00051 void append(const QString &qsText, const QTime &oTime = QTime::currentTime());
00052 void startup();
00053 void shutdown();
00054 static LogImpl g_oLog;
00055 static LogImpl g_oMcu;
00056
00057 signals:
00058 void logline(const QString &qsText, bool bComplete);
00059
00060 private slots:
00061 void settingsChanged();
00062 void timeoutFlush();
00063 void timeoutClose();
00064
00065 private:
00066 QString m_qsType;
00067 QDir m_oPath;
00068 QFile *m_pFile;
00069 QTimer m_oTimerFlush;
00070 QTimer m_oTimerClose;
00071 bool m_bFirstStartup;
00072 bool m_bDoLog;
00073 bool m_bLineComplete;
00074 };
00075
00076
00077 #endif // ASPECT_LOG_H
00078
00079