Logger: Move to shared/

This commit is contained in:
2022-02-27 23:10:46 +01:00
والد bb8906ace4
کامیت 7066cc1a45
2فایلهای تغییر یافته به همراه0 افزوده شده و 0 حذف شده

45
shared/logger.h Normal file
مشاهده پرونده

@@ -0,0 +1,45 @@
#ifndef LOGGER_H
#define LOGGER_H
#include <QFile>
#include <QDebug>
#include <QMutex>
class Logger
{
private:
QDebug *out;
QMutex mutex;
QFile *file;
public:
Logger(QFile *file);
Logger(Logger &&o);
template <class T> Logger &operator<<(const T &val)
{
QMutexLocker locker(&this->mutex);
*out << val;
// TODO: QDebug may not have flushed yet
file->flush();
return *this;
}
template <class T> Logger &operator<<(const T *val)
{
QMutexLocker locker(&this->mutex);
*out << val;
// TODO: QDebug may not have flushed yet
file->flush();
return *this;
}
~Logger()
{
delete out;
}
static Logger &error();
static Logger &info();
};
#endif // LOGGER_H