mirror of
https://github.com/QuasarApp/SoundBand.git
synced 2025-04-28 16:24:32 +00:00
Merge branch 'master' into qmlLogic
This commit is contained in:
commit
c7e0b519cc
@ -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
44
sync/Log.cpp
Normal 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
24
sync/Log.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user