Improved logger

Improved logger
This commit is contained in:
jojos38 2020-01-28 15:47:55 +01:00
parent b3a26c9897
commit 35eebe95ad
3 changed files with 38 additions and 15 deletions

View File

@ -2,29 +2,30 @@
// Created by jojos38 on 28.01.2020.
//
#include "logger.h"
using namespace std;
int level = 0;
int loggerlevel;
void setLoggerLevel(char level_string[]) {
if (!strcmp(level_string, "ALL"))
level = 0;
loggerlevel = 0;
if (!strcmp(level_string, "DEBUG"))
level = 1;
loggerlevel = 1;
if (!strcmp(level_string, "INFO"))
level = 2;
loggerlevel = 2;
if (!strcmp(level_string, "WARN"))
level = 3;
loggerlevel = 3;
if (!strcmp(level_string, "ERROR"))
level = 4;
loggerlevel = 4;
if (!strcmp(level_string, "OFF"))
level = 5;
loggerlevel = 5;
}
stringstream getDate() {
@ -71,6 +72,7 @@ stringstream getDate() {
return date;
}
/*
void info(char obj[]) {
if (level <= 2)
cout << getDate().str() << "\u001b[36m" << "[INFO]" << "\u001b[0m" << " " << obj << endl;
@ -89,4 +91,4 @@ void warn(char obj[]) {
void debug(char obj[]) {
if (level <= 1)
cout << getDate().str() << "\u001b[35m" << "[DBUG]" << "\u001b[0m" << " " << obj << endl;
}
}*/

View File

@ -7,13 +7,35 @@
#include <iostream>
#include <ctime>
#include<sstream>
#include <sstream>
#include <string.h>
using namespace std;
void setLoggerLevel(char level[]);
void info(char obj[]);
void error(char obj[]);
void warn(char obj[]);
void debug(char obj[]);
extern int loggerlevel;
stringstream getDate();
void setLoggerLevel(char level_string[]);
template<typename T>
void info(const T& toPrint) {
if (loggerlevel <= 2)
cout << getDate().str() << "\u001b[36m" << "[INFO]" << "\u001b[0m" << " " << toPrint << endl;
}
template<typename T>
void error(const T& toPrint) {
if (loggerlevel <= 4)
cout << getDate().str() << "\x1B[31m" << "[ERRO]" << "\u001b[0m" << " " << toPrint << endl;
}
template<typename T>
void warn(const T& toPrint) {
if (loggerlevel <= 3)
cout << getDate().str() << "\u001b[33m" << "[WARN]" << "\u001b[0m" << " " << toPrint << endl;
}
template<typename T>
void debug(const T& toPrint) {
if (loggerlevel <= 1)
cout << getDate().str() << "\u001b[35m" << "[DBUG]" << "\u001b[0m" << " " << toPrint << endl;
}
#endif // LOGGER_H

View File

@ -9,6 +9,5 @@
int main() {
// ALL > DEBUG > INFO > WARN > ERROR > OFF
setLoggerLevel("ALL");
startRUDP("localhost", 30814);
}