Merge branch 'master' into qmlLogic

This commit is contained in:
adamsjensen 2018-01-31 14:27:52 +03:00
commit c7e0b519cc
3 changed files with 72 additions and 2 deletions

View File

@ -35,7 +35,8 @@ SOURCES += \
songmodel.cpp \
../sync/player.cpp \
../sync/chronotime.cpp \
../sync/mysql.cpp
../sync/mysql.cpp \
../sync/Log.cpp
HEADERS += \
mainwindow.h \
@ -50,7 +51,8 @@ HEADERS += \
songmodel.h \
../sync/player.h \
../sync/chronotime.h \
../sync/mysql.h
../sync/mysql.h \
../sync/Log.h
FORMS += \
mainwindow.ui

44
sync/Log.cpp Normal file
View File

@ -0,0 +1,44 @@
#include "Log.h"
Log::Log(const QString &fileName)
{
m_showDate = true;
if (!fileName.isEmpty()) {
file = new QFile;
file->setFileName(fileName);
file->open(QIODevice::Append | QIODevice::Text);
}
}
void Log::write(const QString &value, LogType logType) {
QString text = value;// + "";
switch (logType) {
case INFORMATION:
text = "INFORMATION: " + text;
break;
case WARNING:
text = "WARNING: " + text;
break;
case ERROR:
text = "ERROR: " + text;
break;
default:
break;
}
if (m_showDate)
text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + text;
QTextStream out(file);
out.setCodec("UTF-8");
if (file != 0){
out << text + "\n";
}
}
void Log::setShowDateTime(bool value) {
m_showDate = value;
}
Log::~Log() {
if (file != 0)
file->close();
}

24
sync/Log.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef LOG_H
#define LOG_H
#include <QFile>
#include <QTextStream>
#include <QDateTime>
enum LogType{ERROR, WARNING, INFORMATION};
class Log
{
public:
explicit Log(const QString &fileName);
~Log();
void setShowDateTime(bool value);
void write(const QString &value, LogType logType = INFORMATION);
private:
QFile *file;
bool m_showDate;
};
#endif // LOG_H