It is ported to Qt with improved devices and function.
Note
Cmake is not any more supported.
Use Qt. instead of complicated cross-platform code.
UDP client logger has been added.
Other devices will be added. (RDBMS, NoSQL, Bletooth, Serial, DDS, MQ, etc)
Example
1️⃣ How to setup
First, include pri file on your Qt project file(*.pro).
# Define QSLogLib relative path. You can fix this directory# QSLOG_PARENTPATH = ../../# QSLOG_HEADERPATH = ../../QSLogLib/# QSLOG_SOURCEPATH = ../../QSLogLib/include(../../QSLogLib/QSLogLib.pri)
2️⃣ Logging Example for standard output and file
#include<QtGlobal>
#include<QCoreApplication>
#include"QSLogLib/SLogLib.h"
#include"QSLogLib/Devices/AbstractLoggingDevice.h"
#include"QSLogLib/Devices/ConsoleLogger.h"
#include"QSLogLib/Devices/FileLogger.h"
#include"QSLogLib/Devices/UdpLogger.h"
#include"QSLogLib/Formatters/AbstractFormatter.h"
#include"QSLogLib/Formatters/DetailedFormatter.h"
#include"QSLogLib/Formatters/ErrorFormatter.h"
#include"QSLogLib/Formatters/InfoFormatter.h"
#include"QSLogLib/Formatters/NullFormatter.h"intmain(int argc, char *argv[])
{
QCoreApplication mainApp(argc, argv);
usingnamespaceQSLogLib;// add logging device for console and file addLoggingDevice( newConsoleLogger(new NullFormatter) ); // Console + nullFormataddLoggingDevice( newFileLogger("foo.log", new DetailedFormatter) ); // File + detailedFormat// The following line writes the message to both console and file.int a = 10;
double b = 15.3;
constchar* c = "Success";
SLOGLIB_LOG_MSG_INFO("a = " << a << " b = " << b);
SLOGLIB_LOG_MSG_INFO(c);
return0;
}
3️⃣ Logging Example for udp transmission
intmain(int argc, char *argv[])
{
QCoreApplication mainApp(argc, argv);
usingnamespaceQSLogLib;
std::string strDestAddress = "192.168.137.1";
unsignedshort destPort = 5000;
addLoggingDevice(newUdpLogger(strDestAddress, destPort, new NullFormatter));
// The following line writes the message to UDP packet int a = 10;
double b = 15.3;
constchar* c = "Success";
SLOGLIB_LOG_MSG_INFO("a = " << a << " b = " << b);
SLOGLIB_LOG_MSG_INFO(c);
return0;
}