mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-19 09:16:41 +00:00
Update logging with separate log levels
This commit is contained in:
parent
f8c43888a5
commit
1204bdc655
@ -34,16 +34,18 @@ SOFTWARE.
|
||||
void Logging::begin(int level, bool showLevel)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
setLevel(level);
|
||||
setShowLevel(showLevel);
|
||||
setLevel(0, level);
|
||||
setLevel(1, level);
|
||||
setLevel(2, level);
|
||||
setShowLevel(0, showLevel);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Logging::registerOutput(uint8_t slot, Print * logOutput, int level, bool showLevel)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
setLevel(level);
|
||||
setShowLevel(showLevel);
|
||||
setLevel(0, level);
|
||||
setShowLevel(0, showLevel);
|
||||
if(slot >= 3) return;
|
||||
_logOutput[slot] = logOutput;
|
||||
#endif
|
||||
@ -57,33 +59,33 @@ void Logging::unregisterOutput(uint8_t slot)
|
||||
#endif
|
||||
}
|
||||
|
||||
void Logging::setLevel(int level)
|
||||
void Logging::setLevel(uint8_t slot, int level)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
_level = constrain(level, LOG_LEVEL_SILENT, LOG_LEVEL_VERBOSE);
|
||||
_level[slot] = constrain(level, LOG_LEVEL_SILENT, LOG_LEVEL_VERBOSE);
|
||||
#endif
|
||||
}
|
||||
|
||||
int Logging::getLevel() const
|
||||
int Logging::getLevel(uint8_t slot) const
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
return _level;
|
||||
return _level[slot];
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Logging::setShowLevel(bool showLevel)
|
||||
void Logging::setShowLevel(uint8_t slot, bool showLevel)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
_showLevel = showLevel;
|
||||
_showLevel[slot] = showLevel;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Logging::getShowLevel() const
|
||||
bool Logging::getShowLevel(uint8_t slot) const
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
return _showLevel;
|
||||
return _showLevel[slot];
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@ -85,7 +85,7 @@ class Logging {
|
||||
*/
|
||||
Logging()
|
||||
#ifndef DISABLE_LOGGING
|
||||
: _level(LOG_LEVEL_SILENT), _showLevel(true)
|
||||
// : _level(LOG_LEVEL_SILENT), _showLevel(true)
|
||||
#endif
|
||||
{}
|
||||
|
||||
@ -126,14 +126,14 @@ class Logging {
|
||||
* \param level - The new log level.
|
||||
* \return void
|
||||
*/
|
||||
void setLevel(int level);
|
||||
void setLevel(uint8_t slot,int level);
|
||||
|
||||
/**
|
||||
* Get the log level.
|
||||
*
|
||||
* \return The current log level.
|
||||
*/
|
||||
int getLevel() const;
|
||||
int getLevel(uint8_t slot) const;
|
||||
|
||||
/**
|
||||
* Set whether to show the log level.
|
||||
@ -142,7 +142,7 @@ class Logging {
|
||||
* false otherwise.
|
||||
* \return void
|
||||
*/
|
||||
void setShowLevel(bool showLevel);
|
||||
void setShowLevel(uint8_t slot,bool showLevel);
|
||||
|
||||
/**
|
||||
* Get whether the log level is shown during logging
|
||||
@ -150,7 +150,7 @@ class Logging {
|
||||
* \return true if the log level is be shown for each log
|
||||
* false otherwise.
|
||||
*/
|
||||
bool getShowLevel() const;
|
||||
bool getShowLevel(uint8_t slot) const;
|
||||
|
||||
/**
|
||||
* Sets a function to be called before each log command.
|
||||
@ -280,12 +280,9 @@ class Logging {
|
||||
template <class T> void printLevel(int level, T msg, ...)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
if(level > _level) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(uint8_t i = 0; i < 3; i++) {
|
||||
if(_logOutput[i] == NULL) continue;
|
||||
if(_logOutput[i] == NULL || level>_level[i]) continue;
|
||||
|
||||
if(_prefix != NULL) {
|
||||
_prefix(level, _logOutput[i]);
|
||||
@ -304,8 +301,8 @@ class Logging {
|
||||
}
|
||||
|
||||
#ifndef DISABLE_LOGGING
|
||||
int _level;
|
||||
bool _showLevel;
|
||||
int _level[3];
|
||||
bool _showLevel[3];
|
||||
Print * _logOutput[3];
|
||||
|
||||
printfunction _prefix = NULL;
|
||||
|
@ -113,74 +113,6 @@ void debugStart()
|
||||
// log/logf method)
|
||||
}
|
||||
|
||||
// void serialPrintln(const char * debugText, uint8_t level)
|
||||
//{
|
||||
/*
|
||||
String debugTimeText((char *)0);
|
||||
debugTimeText.reserve(128);
|
||||
|
||||
uint8_t heapfrag = halGetHeapFragmentation();
|
||||
debugTimeText = F("[");
|
||||
debugTimeText += String(float(millis()) / 1000, 3);
|
||||
debugTimeText += F("s] ");
|
||||
debugTimeText += halGetMaxFreeBlock();
|
||||
debugTimeText += F("/");
|
||||
debugTimeText += ESP.getFreeHeap();
|
||||
debugTimeText += F(" ");
|
||||
if(heapfrag < 10) debugTimeText += F(" ");
|
||||
debugTimeText += heapfrag;
|
||||
debugTimeText += F(" ");
|
||||
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
lv_mem_monitor_t mem_mon;
|
||||
lv_mem_monitor(&mem_mon);
|
||||
debugTimeText += F("| ");
|
||||
debugTimeText += mem_mon.used_pct;
|
||||
debugTimeText += F("% ");
|
||||
debugTimeText += mem_mon.free_biggest_size;
|
||||
debugTimeText += F("b/");
|
||||
debugTimeText += mem_mon.free_size;
|
||||
debugTimeText += F("b ");
|
||||
debugTimeText += (mem_mon.total_size - mem_mon.free_size);
|
||||
debugTimeText += F("b | ");
|
||||
#endif
|
||||
|
||||
if(debugSerialStarted) {
|
||||
// Serial.print(debugTimeText);
|
||||
// Serial.println(debugText);
|
||||
}/
|
||||
|
||||
switch(level) {
|
||||
case LOG_LEVEL_FATAL:
|
||||
Log.fatal(debugText);
|
||||
break;
|
||||
case LOG_LEVEL_ERROR:
|
||||
Log.error(debugText);
|
||||
break;
|
||||
case LOG_LEVEL_WARNING:
|
||||
Log.warning(debugText);
|
||||
break;
|
||||
case LOG_LEVEL_VERBOSE:
|
||||
Log.verbose(debugText);
|
||||
break;
|
||||
case LOG_LEVEL_TRACE:
|
||||
Log.trace(debugText);
|
||||
break;
|
||||
default:
|
||||
Log.notice(debugText);
|
||||
}
|
||||
|
||||
#if HASP_USE_TELNET != 0
|
||||
// telnetPrint(debugTimeText.c_str());
|
||||
telnetPrintln(debugText);
|
||||
#endif
|
||||
}
|
||||
|
||||
void serialPrintln(String & debugText, uint8_t level)
|
||||
{
|
||||
serialPrintln(debugText.c_str(), level);
|
||||
} */
|
||||
|
||||
#if HASP_USE_SYSLOG != 0
|
||||
void syslogSend(uint8_t priority, const char * debugText)
|
||||
{
|
||||
@ -256,20 +188,6 @@ bool debugSetConfig(const JsonObject & settings)
|
||||
return changed;
|
||||
}
|
||||
|
||||
/*
|
||||
void debugSendOuput(const char * buffer)
|
||||
{
|
||||
if(debugSerialStarted) Serial.print(buffer);
|
||||
telnetPrint(buffer);
|
||||
}
|
||||
|
||||
void debugSendOuput(const __FlashStringHelper * txt)
|
||||
{
|
||||
if(debugSerialStarted) Serial.print(txt);
|
||||
telnetPrint(txt);
|
||||
}
|
||||
*/
|
||||
|
||||
inline void debugSendAnsiCode(const __FlashStringHelper * code, Print * _logOutput)
|
||||
{
|
||||
if(debugAnsiCodes) _logOutput->print(code);
|
||||
@ -283,12 +201,14 @@ static void debugPrintTimestamp(int level, Print * _logOutput)
|
||||
time(&rawtime);
|
||||
timeinfo = localtime(&rawtime);
|
||||
|
||||
// strftime(buffer, sizeof(buffer), "%b %d %H:%M:%S.", timeinfo);
|
||||
// Serial.println(buffer);
|
||||
|
||||
debugSendAnsiCode(F(TERM_COLOR_CYAN), _logOutput);
|
||||
// strftime(buffer, sizeof(buffer), ("[%b %d %H:%M:%S."), timeinfo);
|
||||
// strftime(buffer, sizeof(buffer), ("[%H:%M:%S."), timeinfo);
|
||||
if(timeinfo->tm_year >= 2020) {
|
||||
|
||||
if(timeinfo->tm_year >= 120) {
|
||||
char buffer[64];
|
||||
strftime(buffer, sizeof(buffer), PSTR("[%b %d %H:%M:%S."), timeinfo); // Literal String
|
||||
strftime(buffer, sizeof(buffer), "[%b %d %H:%M:%S.", timeinfo); // Literal String
|
||||
_logOutput->print(buffer);
|
||||
_logOutput->printf(PSTR("%03u]"), millis() % 1000);
|
||||
} else {
|
||||
@ -311,7 +231,7 @@ static void debugPrintHaspMemory(int level, Print * _logOutput)
|
||||
else
|
||||
debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput);
|
||||
}
|
||||
_logOutput->printf(PSTR("[%5u/%5u %2u] "), maxfree, totalfree, frag);
|
||||
_logOutput->printf(PSTR("[%5u/%5u%3u]"), maxfree, totalfree, frag);
|
||||
}
|
||||
|
||||
#if LV_MEM_CUSTOM == 0
|
||||
@ -330,7 +250,7 @@ static void debugPrintLvglMemory(int level, Print * _logOutput)
|
||||
else
|
||||
debugSendAnsiCode(F(TERM_COLOR_RED), _logOutput);
|
||||
}
|
||||
_logOutput->printf(PSTR("[%5u/%5u %2u] "), mem_mon.free_biggest_size, mem_mon.free_size, mem_mon.frag_pct);
|
||||
_logOutput->printf(PSTR("[%5u/%5u%3u]"), mem_mon.free_biggest_size, mem_mon.free_size, mem_mon.frag_pct);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -383,7 +303,8 @@ void debugPreSetup(JsonObject settings)
|
||||
{
|
||||
// Link stream to debugOutput
|
||||
// debugOutput.reserve(512);
|
||||
Log.begin(LOG_LEVEL_VERBOSE, true);
|
||||
|
||||
Log.begin(LOG_LEVEL_WARNING, true);
|
||||
Log.setPrefix(debugPrintPrefix); // Uncomment to get timestamps as prefix
|
||||
Log.setSuffix(debugPrintSuffix); // Uncomment to get newline as suffix
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user