"c++ logger class example" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "c++ logger class example" answered properly. Developers are finding an appropriate answer about c++ logger class example related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like c++ logger class example. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on c++ logger class example.
c++ logger class example
/*
Usage:
*/
#include "Log.h"
int main(int argc, char** argv) {
//Config: -----(optional)----
structlog LOGCFG = {};
LOGCFG.headers = false;
LOGCFG.level = DEBUG;
//---------------------------
LOG(INFO) << "Main executed with " << (argc - 1) << " arguments";
}
/*
* File: Log.h
* Author: Alberto Lepe <[email protected]>
*
* Created on December 1, 2015, 6:00 PM
*/
#ifndef LOG_H
#define LOG_H
#include <iostream>
using namespace std;
enum typelog {
DEBUG,
INFO,
WARN,
ERROR
};
struct structlog {
bool headers = false;
typelog level = WARN;
};
extern structlog LOGCFG;
class LOG {
public:
LOG() {}
LOG(typelog type) {
msglevel = type;
if(LOGCFG.headers) {
operator << ("["+getLabel(type)+"]");
}
}
~LOG() {
if(opened) {
cout << endl;
}
opened = false;
}
template<class T>
LOG &operator<<(const T &msg) {
if(msglevel >= LOGCFG.level) {
cout << msg;
opened = true;
}
return *this;
}
private:
bool opened = false;
typelog msglevel = DEBUG;
inline string getLabel(typelog type) {
string label;
switch(type) {
case DEBUG: label = "DEBUG"; break;
case INFO: label = "INFO "; break;
case WARN: label = "WARN "; break;
case ERROR: label = "ERROR"; break;
}
return label;
}
};
#endif /* LOG_H */
Source: stackoverflow.com
All those coders who are working on the C++ based application and are stuck on c++ logger class example can get a collection of related answers to their query. Programmers need to enter their query on c++ logger class example related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about c++ logger class example for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of c++ logger class example while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "c++ logger class example". Visit this developer's friendly online web community, CodeProZone, and get your queries like c++ logger class example resolved professionally and stay updated to the latest C++ updates.