#58 - Add connection logging
This commit is contained in:
26
src/logger.cpp
Normal file
26
src/logger.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "logger.h"
|
||||||
|
|
||||||
|
Logger::Logger(QObject *parent, QString fileName) : QObject(parent) {
|
||||||
|
m_showDate = true;
|
||||||
|
if (!fileName.isEmpty()) {
|
||||||
|
file = new QFile;
|
||||||
|
file->setFileName(fileName);
|
||||||
|
file->open(QIODevice::Append | QIODevice::Text);
|
||||||
|
}
|
||||||
|
write("=========Startup==========");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Logger::write(const QString &value) {
|
||||||
|
QString text = value;// + "";
|
||||||
|
text = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss ") + text;
|
||||||
|
QTextStream out(file);
|
||||||
|
out.setCodec("UTF-8");
|
||||||
|
if (file != 0) {
|
||||||
|
out << text << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::~Logger() {
|
||||||
|
if (file != 0)
|
||||||
|
file->close();
|
||||||
|
}
|
||||||
23
src/logger.h
Normal file
23
src/logger.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef LOGGER_H
|
||||||
|
#define LOGGER_H
|
||||||
|
|
||||||
|
#include "precompiled.h"
|
||||||
|
|
||||||
|
class Logger : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Logger(QObject *parent, QString fileName);
|
||||||
|
~Logger();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QFile *file;
|
||||||
|
bool m_showDate;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void write(const QString &value);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LOGGER_H
|
||||||
@@ -49,7 +49,8 @@ SOURCES += \
|
|||||||
src/qrcodelabel.cpp \
|
src/qrcodelabel.cpp \
|
||||||
src/connection.cpp \
|
src/connection.cpp \
|
||||||
src/fillediconlabel.cpp \
|
src/fillediconlabel.cpp \
|
||||||
src/addressbook.cpp
|
src/addressbook.cpp \
|
||||||
|
src/logger.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/mainwindow.h \
|
src/mainwindow.h \
|
||||||
@@ -67,7 +68,8 @@ HEADERS += \
|
|||||||
src/qrcodelabel.h \
|
src/qrcodelabel.h \
|
||||||
src/connection.h \
|
src/connection.h \
|
||||||
src/fillediconlabel.h \
|
src/fillediconlabel.h \
|
||||||
src/addressbook.h
|
src/addressbook.h \
|
||||||
|
src/logger.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
src/mainwindow.ui \
|
src/mainwindow.ui \
|
||||||
|
|||||||
Reference in New Issue
Block a user