diff --git a/logger.cpp b/logger.cpp index 27b1237..bd302e6 100644 --- a/logger.cpp +++ b/logger.cpp @@ -50,13 +50,24 @@ void Logger::makeStartingLine() } } +/*******************************************************************************************/ +void Logger::logReceivedData(const QByteArray& msg, const QHostAddress& addr, quint16 port) +{ + qDebug() << "Address: " << addr.toString() << " - " << "Port: " << port << " - " << + "Content: " << msg << '\n'; +} + +void Logger::logReceivedData(const QString& msg) +{ + qDebug() << "Log : " << msg << '\n'; +} + /*******************************************************************************************/ void Logger::messageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg) { - QString log = QObject::tr("%1 | %2 | %3 | %4 | %5\n"). + QString log = QObject::tr("%1 | %2 | %3 | %4\n"). arg(QDateTime::currentDateTime().toString("yyyy/MM/dd - hh:mm:ss")). arg(Logger::_logTitles.value(type)). - arg(context.line). arg(QString(context.function).section('(', -2, -2). //Function name only section(' ', -1). section(':', -1)). diff --git a/logger.h b/logger.h index dd9d9a0..6b71534 100644 --- a/logger.h +++ b/logger.h @@ -4,6 +4,7 @@ #include #include #include +#include class Logger { @@ -15,6 +16,9 @@ public: Logger(const QString& fileName = "./DefaultHatefLogFile.log"); ~Logger(); + static void logReceivedData(const QByteArray& msg, const QHostAddress& addr, quint16 port); + static void logReceivedData(const QString& msg); + static void makeStartingLine(); static void clearLog(); static void messageOutput(QtMsgType type, const QMessageLogContext& context, diff --git a/main.cpp b/main.cpp index a423226..0f83e76 100644 --- a/main.cpp +++ b/main.cpp @@ -6,8 +6,8 @@ int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); - Logger mylog("thetest7.log"); - //mylog.clearLog(); + Logger mylog("thetest8.log"); + mylog.clearLog(); Logger::makeStartingLine(); UdpSocket server; @@ -15,8 +15,8 @@ int main(int argc, char* argv[]) client.sayHello(); server.sayHello(); - client.sayMsg("MsgC"); - server.sayMsg("MsgS"); + client.sayMsg("Msg1C"); + server.sayMsg("Msg1S"); return a.exec(); } diff --git a/socket.cpp b/socket.cpp index a889b4f..776525d 100644 --- a/socket.cpp +++ b/socket.cpp @@ -1,3 +1,4 @@ +#include "logger.h" #include "socket.h" UdpSocket::UdpSocket(QObject* parent, quint16 port) : @@ -31,14 +32,6 @@ void UdpSocket::sayMsg(const QString& msg) _socket->writeDatagram(Data, QHostAddress::LocalHost, _port); } -/*******************************************************************************************/ -void UdpSocket::logReceivedData(const QHostAddress& addr, quint16 port, const QByteArray& msg) const -{ - qDebug() << "Address : " << addr.toString(); - qDebug() << "Port : " << port; - qDebug() << "Content : " << msg << '\n'; -} - /*******************************************************************************************/ void UdpSocket::readyRead() { @@ -47,5 +40,5 @@ void UdpSocket::readyRead() QHostAddress sender_addr; quint16 sender_port; _socket->readDatagram(buffer.data(), buffer.size(), &sender_addr, &sender_port); - logReceivedData(sender_addr, sender_port, buffer); + Logger::logReceivedData(buffer, sender_addr, sender_port); } diff --git a/socket.h b/socket.h index 99278a1..3bb4da5 100644 --- a/socket.h +++ b/socket.h @@ -12,8 +12,6 @@ private: QUdpSocket* _socket; const quint16 _port; - void logReceivedData(const QHostAddress& addr, quint16 port, const QByteArray& msg) const; - public: explicit UdpSocket(QObject* parent = nullptr, quint16 port = 1234); ~UdpSocket();