-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.cpp
More file actions
41 lines (40 loc) · 1.25 KB
/
Copy pathlogger.cpp
File metadata and controls
41 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "logger.h"
namespace app
{
LOG_LEVEL loglevel = LOG_MSG;
namespace
{
QMutex stdioLock;
QString levels[4] = {"MISC", "MSG", "ERROR", "FATAL"};
}
void log(const QString& message, LOG_LEVEL level)
{
if (level >= app::loglevel)
{
QMutexLocker _lock(&stdioLock);
((level >= 2) ? (std::cerr) : (std::cout)) << (QString("%1 [%2] %3\n").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"), levels[level], message)).toStdString();
}
}
QString query(const QString& query)
{
QMutexLocker _lock(&stdioLock);
std::string reply;
std::cout << (QString("%1 [%2] %3").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"), "QUERY", query)).toStdString();
std::cin >> reply;
return QString::fromStdString(reply);
}
QStringList query(const QStringList& queries)
{
QMutexLocker _lock(&stdioLock);
std::string reply;
QStringList results;
for (int i = 0; i < queries.size(); i++)
{
std::cout << (QString("%1 [%2] %3").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"), "QUERY", queries[i])).toStdString();
reply.clear();
std::cin >> reply;
results.push_back(QString::fromStdString(reply));
}
return results;
}
} // namespace app