-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.cpp
More file actions
64 lines (54 loc) · 2.16 KB
/
logger.cpp
File metadata and controls
64 lines (54 loc) · 2.16 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "logger.h"
#include <string>
#include <iostream>
Logger* Logger::loggerInst = nullptr;
Logger::Logger(QObject& guiObject)
{
this->guiObject = &guiObject;
Logger::loggerInst = this;
}
void Logger::debug(std::string message) {
if(Logger::loglevel <= 1) {
std::cout << "Debug: " << message << std::endl;
if(Logger::loglevel <= 0) printLn(QString::fromStdString("<p style=\"color:blue\">Debug: " + message + "</p>"));
}
}
void Logger::debug(std::string message, sint value) {
if(Logger::loglevel <= 1) {
std::cout << "Debug: " << message << value << std::endl;
if(Logger::loglevel <= 0) printLn(QString::fromStdString("<p style=\"color:blue\">Debug: " + message) + QVariant::fromValue(value).toString() + "</p>");
}
}
void Logger::info(std::string message) {
if(Logger::loglevel <= 2) {
std::cout << "Info: " << message << std::endl;
printLn(QString::fromStdString("<p style=\"color:green\">Info: " + message + "</p>"));
}
}
void Logger::warning(std::string message) {
if(Logger::loglevel <= 3) {
std::cout << "Warning: " << message << std::endl;
printLn(QString::fromStdString("<p style=\"color:#ffaa00\">Warning: " + message + "</p>"));
}
}
void Logger::warning(std::string message, sint value) {
if(Logger::loglevel <= 3) {
std::cout << "Warning: " << message << value << std::endl;
printLn(QString::fromStdString("<p style=\"color:#ffaa00\">Warning: " + message) + QVariant::fromValue(value).toString() + "</p>");
}
}
void Logger::error(std::string message) {
if(Logger::loglevel <= 4) {
std::cerr << "Error: " << message << std::endl;
printLn(QString::fromStdString("<p style=\"color:red\">Error: " + message + "</p>"));
}
}
void Logger::error(std::string message, sint value) {
if(Logger::loglevel <= 4) {
std::cerr << "Error: " << message << value << std::endl;
printLn(QString::fromStdString("<p style=\"color:red\">Error: " + message) + QVariant::fromValue(value).toString() + "</p>");
}
}
void Logger::printLn(const QString &line) {
QMetaObject::invokeMethod(guiObject,"printLine",Q_ARG(QVariant,line));
}