Skip to content

Commit

Permalink
Include log levels for debug messages
Browse files Browse the repository at this point in the history
Signed-off-by: Jobin Johnson <[email protected]>
  • Loading branch information
jobinrjohnson committed Jan 27, 2019
1 parent 36fbd4a commit a1191b5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
5 changes: 2 additions & 3 deletions QSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

using namespace std;

extern int a;
int a=30;
int LOG_LEVEL = LOG_LEVEL_VERBOSE;

int main(int argc, char **argv) {

printdebug("Hey There : ");
printdebug(LOG_LEVEL_INFO, "Simulator Started");
return 0;

}
Expand Down
12 changes: 11 additions & 1 deletion utils/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
#ifndef UTILS_UTIL_H_
#define UTILS_UTIL_H_

extern void printdebug(const char*);
// LOG LEVELS
#define LOG_LEVEL_VERBOSE 0
#define LOG_LEVEL_INFO 1
#define LOG_LEVEL_WARN 2
#define LOG_LEVEL_ERROR 3
#define LOG_LEVEL_FATAL 4

extern int LOG_LEVEL;

extern void printdebug(unsigned short int, const char*);
extern char getLevel(unsigned short int);

#endif /* UTILS_UTIL_H_ */
35 changes: 33 additions & 2 deletions utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,39 @@
#include <util.h>
#include <iostream>

void printdebug(const char* message){
std::cout << message;
char getLevel(unsigned short int level) {
char type;
switch (level) {
case LOG_LEVEL_VERBOSE:
type = 'V';
break;
case LOG_LEVEL_INFO:
type = 'I';
break;
case LOG_LEVEL_WARN:
type = 'W';
break;
case LOG_LEVEL_ERROR:
type = 'E';
break;
case LOG_LEVEL_FATAL:
type = 'F';
break;
default:
type = 'V';
}

return type;
}

void printdebug(unsigned short int level, const char* message) {
char type = getLevel(level);

if (level < LOG_LEVEL) {
return;
}

std::cout << type << ": " << message << "\n";
// TODO add debugging options
}

0 comments on commit a1191b5

Please sign in to comment.