introduce debug log
This commit is contained in:
parent
149ffb7a5f
commit
2057b70cb7
|
@ -1,7 +1,8 @@
|
||||||
#include "GwLog.h"
|
#include "GwLog.h"
|
||||||
|
|
||||||
GwLog::GwLog(bool logSerial){
|
GwLog::GwLog(bool logSerial, int level){
|
||||||
this->logSerial=logSerial;
|
this->logSerial=logSerial;
|
||||||
|
logLevel=level;
|
||||||
}
|
}
|
||||||
void GwLog::logString(const char *fmt,...){
|
void GwLog::logString(const char *fmt,...){
|
||||||
va_list args;
|
va_list args;
|
||||||
|
@ -12,3 +13,13 @@ void GwLog::logString(const char *fmt,...){
|
||||||
Serial.println(buffer);
|
Serial.println(buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void GwLog::logDebug(int level,const char *fmt,...){
|
||||||
|
if (level > logLevel) return;
|
||||||
|
va_list args;
|
||||||
|
va_start(args,fmt);
|
||||||
|
vsnprintf(buffer,99,fmt,args);
|
||||||
|
if (logSerial){
|
||||||
|
Serial.print("LOG: ");
|
||||||
|
Serial.println(buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,8 +5,17 @@ class GwLog{
|
||||||
private:
|
private:
|
||||||
char buffer[100];
|
char buffer[100];
|
||||||
bool logSerial=false;
|
bool logSerial=false;
|
||||||
|
int logLevel=1;
|
||||||
public:
|
public:
|
||||||
GwLog(bool logSerial);
|
static const int LOG=1;
|
||||||
|
static const int ERROR=0;
|
||||||
|
static const int DEBUG=3;
|
||||||
|
static const int TRACE=2;
|
||||||
|
GwLog(bool logSerial,int level=LOG);
|
||||||
void logString(const char *fmt,...);
|
void logString(const char *fmt,...);
|
||||||
|
void logDebug(int level, const char *fmt,...);
|
||||||
|
int isActive(int level){return level <= logLevel;};
|
||||||
};
|
};
|
||||||
|
#define LOG_DEBUG(level,fmt,...){ if (logger->isActive(level)) logger->logDebug(level,fmt,__VA_ARGS__);}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -37,7 +37,8 @@
|
||||||
#include "GwBoatData.h"
|
#include "GwBoatData.h"
|
||||||
|
|
||||||
|
|
||||||
GwLog logger(LOG_SERIAL);
|
|
||||||
|
GwLog logger(LOG_SERIAL,GwLog::DEBUG);
|
||||||
GwConfigHandler config(&logger);
|
GwConfigHandler config(&logger);
|
||||||
GwWifi gwWifi(&config,&logger);
|
GwWifi gwWifi(&config,&logger);
|
||||||
GwSocketServer socketServer(&config,&logger);
|
GwSocketServer socketServer(&config,&logger);
|
||||||
|
|
Loading…
Reference in New Issue