Skip to content

Commit

Permalink
Merge pull request #2081 from meshtastic/log-levels
Browse files Browse the repository at this point in the history
Created more structured enterprisey logging with levels
  • Loading branch information
thebentern authored Dec 30, 2022
2 parents 8ebe0ed + 3d3aba5 commit 69ff724
Show file tree
Hide file tree
Showing 92 changed files with 1,069 additions and 1,062 deletions.
22 changes: 11 additions & 11 deletions src/ButtonThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ class ButtonThread : public concurrency::OSThread
userButtonTouch.tick();
canSleep &= userButtonTouch.isIdle();
#endif
// if (!canSleep) DEBUG_MSG("Supressing sleep!\n");
// else DEBUG_MSG("sleep ok\n");
// if (!canSleep) LOG_DEBUG("Supressing sleep!\n");
// else LOG_DEBUG("sleep ok\n");

return 5;
}
Expand All @@ -108,12 +108,12 @@ class ButtonThread : public concurrency::OSThread
static void touchPressed()
{
screen->forceDisplay();
DEBUG_MSG("touch press!\n");
LOG_DEBUG("touch press!\n");
}

static void userButtonPressed()
{
// DEBUG_MSG("press!\n");
// LOG_DEBUG("press!\n");
#ifdef BUTTON_PIN
if ((BUTTON_PIN != moduleConfig.canned_message.inputbroker_pin_press) ||
!moduleConfig.canned_message.enabled) {
Expand All @@ -123,7 +123,7 @@ class ButtonThread : public concurrency::OSThread
}
static void userButtonPressedLong()
{
// DEBUG_MSG("Long press!\n");
// LOG_DEBUG("Long press!\n");
#ifdef ARCH_ESP32
screen->adjustBrightness();
#endif
Expand All @@ -139,7 +139,7 @@ class ButtonThread : public concurrency::OSThread
// may wake the board immediatedly.
if ((!shutdown_on_long_stop) && (millis() > 30 * 1000)) {
screen->startShutdownScreen();
DEBUG_MSG("Shutdown from long press");
LOG_INFO("Shutdown from long press");
playBeep();
#ifdef PIN_LED1
ledOff(PIN_LED1);
Expand All @@ -154,7 +154,7 @@ class ButtonThread : public concurrency::OSThread
}
#endif
} else {
// DEBUG_MSG("Long press %u\n", (millis() - longPressTime));
// LOG_DEBUG("Long press %u\n", (millis() - longPressTime));
}
}

Expand All @@ -166,11 +166,11 @@ class ButtonThread : public concurrency::OSThread
#if defined(GPS_POWER_TOGGLE)
if(config.position.gps_enabled)
{
DEBUG_MSG("Flag set to false for gps power\n");
LOG_DEBUG("Flag set to false for gps power\n");
}
else
{
DEBUG_MSG("Flag set to true to restore power\n");
LOG_DEBUG("Flag set to true to restore power\n");
}
config.position.gps_enabled = !(config.position.gps_enabled);
doGPSpowersave(config.position.gps_enabled);
Expand All @@ -187,15 +187,15 @@ class ButtonThread : public concurrency::OSThread
static void userButtonPressedLongStart()
{
if (millis() > 30 * 1000) {
DEBUG_MSG("Long press start!\n");
LOG_DEBUG("Long press start!\n");
longPressTime = millis();
}
}

static void userButtonPressedLongStop()
{
if (millis() > 30 * 1000) {
DEBUG_MSG("Long press stop!\n");
LOG_DEBUG("Long press stop!\n");
longPressTime = 0;
if (shutdown_on_long_stop) {
playShutdownMelody();
Expand Down
22 changes: 19 additions & 3 deletions src/DebugConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,33 @@
#define SERIAL_BAUD 115200 // Serial debug baud rate
#endif

#define MESHTASTIC_LOG_LEVEL_DEBUG "DEBUG"
#define MESHTASTIC_LOG_LEVEL_INFO "INFO "
#define MESHTASTIC_LOG_LEVEL_WARN "WARN "
#define MESHTASTIC_LOG_LEVEL_ERROR "ERROR"
#define MESHTASTIC_LOG_LEVEL_TRACE "TRACE"

#include "SerialConsole.h"

#define DEBUG_PORT (*console) // Serial debug port

#ifdef USE_SEGGER
#define DEBUG_MSG(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#define LOG_DEBUG(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#define LOG_INFO(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#define LOG_WARN(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#define LOG_ERROR(...) SEGGER_RTT_printf(0, __VA_ARGS__)
#else
#ifdef DEBUG_PORT
#define DEBUG_MSG(...) DEBUG_PORT.logDebug(__VA_ARGS__)
#define LOG_DEBUG(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_DEBUG, __VA_ARGS__)
#define LOG_INFO(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_INFO, __VA_ARGS__)
#define LOG_WARN(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_WARN, __VA_ARGS__)
#define LOG_ERROR(...) DEBUG_PORT.log(MESHTASTIC_LOG_LEVEL_ERROR, __VA_ARGS__)
#define LOG_TRACE(...) DEBUG_PORT.log(MESHTASTIC_LOG_TRACE, __VA_ARGS__)
#else
#define DEBUG_MSG(...)
#define LOG_DEBUG(...)
#define LOG_INFO(...)
#define LOG_WARN(...)
#define LOG_ERROR(...)
#endif
#endif

Expand Down
48 changes: 24 additions & 24 deletions src/FSCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ bool copyFile(const char* from, const char* to)

File f1 = FSCom.open(from, FILE_O_READ);
if (!f1){
DEBUG_MSG("Failed to open source file %s\n", from);
LOG_ERROR("Failed to open source file %s\n", from);
return false;
}

File f2 = FSCom.open(to, FILE_O_WRITE);
if (!f2) {
DEBUG_MSG("Failed to open destination file %s\n", to);
LOG_ERROR("Failed to open destination file %s\n", to);
return false;
}

Expand Down Expand Up @@ -79,7 +79,7 @@ void listDir(const char * dirname, uint8_t levels, boolean del = false)
#ifdef ARCH_ESP32
listDir(file.path(), levels -1, del);
if(del) {
DEBUG_MSG("Removing %s\n", file.path());
LOG_DEBUG("Removing %s\n", file.path());
strcpy(buffer, file.path());
file.close();
FSCom.rmdir(buffer);
Expand All @@ -89,7 +89,7 @@ void listDir(const char * dirname, uint8_t levels, boolean del = false)
#elif (defined(ARCH_RP2040) || defined(ARCH_PORTDUINO))
listDir(file.name(), levels -1, del);
if(del) {
DEBUG_MSG("Removing %s\n", file.name());
LOG_DEBUG("Removing %s\n", file.name());
strcpy(buffer, file.name());
file.close();
FSCom.rmdir(buffer);
Expand All @@ -104,34 +104,34 @@ void listDir(const char * dirname, uint8_t levels, boolean del = false)
} else {
#ifdef ARCH_ESP32
if(del) {
DEBUG_MSG("Deleting %s\n", file.path());
LOG_DEBUG("Deleting %s\n", file.path());
strcpy(buffer, file.path());
file.close();
FSCom.remove(buffer);
} else {
DEBUG_MSG(" %s (%i Bytes)\n", file.path(), file.size());
LOG_DEBUG(" %s (%i Bytes)\n", file.path(), file.size());
file.close();
}
#elif (defined(ARCH_RP2040) || defined(ARCH_PORTDUINO))
if(del) {
DEBUG_MSG("Deleting %s\n", file.name());
LOG_DEBUG("Deleting %s\n", file.name());
strcpy(buffer, file.name());
file.close();
FSCom.remove(buffer);
} else {
DEBUG_MSG(" %s (%i Bytes)\n", file.name(), file.size());
LOG_DEBUG(" %s (%i Bytes)\n", file.name(), file.size());
file.close();
}
#else
DEBUG_MSG(" %s (%i Bytes)\n", file.name(), file.size());
LOG_DEBUG(" %s (%i Bytes)\n", file.name(), file.size());
file.close();
#endif
}
file = root.openNextFile();
}
#ifdef ARCH_ESP32
if(del) {
DEBUG_MSG("Removing %s\n", root.path());
LOG_DEBUG("Removing %s\n", root.path());
strcpy(buffer, root.path());
root.close();
FSCom.rmdir(buffer);
Expand All @@ -140,7 +140,7 @@ void listDir(const char * dirname, uint8_t levels, boolean del = false)
}
#elif (defined(ARCH_RP2040) || defined(ARCH_PORTDUINO))
if(del) {
DEBUG_MSG("Removing %s\n", root.name());
LOG_DEBUG("Removing %s\n", root.name());
strcpy(buffer, root.name());
root.close();
FSCom.rmdir(buffer);
Expand Down Expand Up @@ -170,13 +170,13 @@ void fsInit()
#ifdef FSCom
if (!FSBegin())
{
DEBUG_MSG("ERROR filesystem mount Failed. Formatting...\n");
LOG_ERROR("Filesystem mount Failed. Formatting...\n");
assert(0); // FIXME - report failure to phone
}
#ifdef ARCH_ESP32
DEBUG_MSG("Filesystem files (%d/%d Bytes):\n", FSCom.usedBytes(), FSCom.totalBytes());
LOG_DEBUG("Filesystem files (%d/%d Bytes):\n", FSCom.usedBytes(), FSCom.totalBytes());
#else
DEBUG_MSG("Filesystem files:\n");
LOG_DEBUG("Filesystem files:\n");
#endif
listDir("/", 10);
#endif
Expand All @@ -189,29 +189,29 @@ void setupSDCard()
SDHandler.begin(SPI_SCK, SPI_MISO, SPI_MOSI);

if (!SD.begin(SDCARD_CS, SDHandler)) {
DEBUG_MSG("No SD_MMC card detected\n");
LOG_DEBUG("No SD_MMC card detected\n");
return ;
}
uint8_t cardType = SD.cardType();
if (cardType == CARD_NONE) {
DEBUG_MSG("No SD_MMC card attached\n");
LOG_DEBUG("No SD_MMC card attached\n");
return ;
}
DEBUG_MSG("SD_MMC Card Type: ");
LOG_DEBUG("SD_MMC Card Type: ");
if (cardType == CARD_MMC) {
DEBUG_MSG("MMC\n");
LOG_DEBUG("MMC\n");
} else if (cardType == CARD_SD) {
DEBUG_MSG("SDSC\n");
LOG_DEBUG("SDSC\n");
} else if (cardType == CARD_SDHC) {
DEBUG_MSG("SDHC\n");
LOG_DEBUG("SDHC\n");
} else {
DEBUG_MSG("UNKNOWN\n");
LOG_DEBUG("UNKNOWN\n");
}

uint64_t cardSize = SD.cardSize() / (1024 * 1024);
DEBUG_MSG("SD Card Size: %lluMB\n", cardSize);
DEBUG_MSG("Total space: %llu MB\n", SD.totalBytes() / (1024 * 1024));
DEBUG_MSG("Used space: %llu MB\n", SD.usedBytes() / (1024 * 1024));
LOG_DEBUG("SD Card Size: %lluMB\n", cardSize);
LOG_DEBUG("Total space: %llu MB\n", SD.totalBytes() / (1024 * 1024));
LOG_DEBUG("Used space: %llu MB\n", SD.usedBytes() / (1024 * 1024));
#endif
}

Expand Down
14 changes: 7 additions & 7 deletions src/GPSStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GPSStatus : public Status
{
if (config.position.fixed_position) {
#ifdef GPS_EXTRAVERBOSE
DEBUG_MSG("WARNING: Using fixed latitude\n");
LOG_WARN("Using fixed latitude\n");
#endif
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.latitude_i;
Expand All @@ -66,7 +66,7 @@ class GPSStatus : public Status
{
if (config.position.fixed_position) {
#ifdef GPS_EXTRAVERBOSE
DEBUG_MSG("WARNING: Using fixed longitude\n");
LOG_WARN("Using fixed longitude\n");
#endif
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.longitude_i;
Expand All @@ -79,7 +79,7 @@ class GPSStatus : public Status
{
if (config.position.fixed_position) {
#ifdef GPS_EXTRAVERBOSE
DEBUG_MSG("WARNING: Using fixed altitude\n");
LOG_WARN("Using fixed altitude\n");
#endif
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
return node->position.altitude;
Expand All @@ -97,7 +97,7 @@ class GPSStatus : public Status
bool matches(const GPSStatus *newStatus) const
{
#ifdef GPS_EXTRAVERBOSE
DEBUG_MSG("GPSStatus.match() new pos@%x to old pos@%x\n", newStatus->p.pos_timestamp, p.pos_timestamp);
LOG_DEBUG("GPSStatus.match() new pos@%x to old pos@%x\n", newStatus->p.pos_timestamp, p.pos_timestamp);
#endif
return (newStatus->hasLock != hasLock || newStatus->isConnected != isConnected || newStatus->isPowerSaving !=isPowerSaving ||
newStatus->p.latitude_i != p.latitude_i || newStatus->p.longitude_i != p.longitude_i ||
Expand All @@ -114,7 +114,7 @@ class GPSStatus : public Status

if (isDirty && p.timestamp && (newStatus->p.timestamp == p.timestamp)) {
// We can NEVER be in two locations at the same time! (also PR #886)
DEBUG_MSG("BUG!! positional timestamp unchanged from prev solution\n");
LOG_ERROR("BUG: Positional timestamp unchanged from prev solution\n");
}

initialized = true;
Expand All @@ -126,11 +126,11 @@ class GPSStatus : public Status
if (isDirty) {
if (hasLock) {
// In debug logs, identify position by @timestamp:stage (stage 3 = notify)
DEBUG_MSG("New GPS pos@%x:3 lat=%f, lon=%f, alt=%d, pdop=%.2f, track=%.2f, speed=%.2f, sats=%d\n", p.timestamp,
LOG_DEBUG("New GPS pos@%x:3 lat=%f, lon=%f, alt=%d, pdop=%.2f, track=%.2f, speed=%.2f, sats=%d\n", p.timestamp,
p.latitude_i * 1e-7, p.longitude_i * 1e-7, p.altitude, p.PDOP * 1e-2, p.ground_track * 1e-5,
p.ground_speed * 1e-2, p.sats_in_view);
} else
DEBUG_MSG("No GPS lock\n");
LOG_DEBUG("No GPS lock\n");
onNewStatus.notifyObservers(this);
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace meshtastic {
numTotal = newStatus->getNumTotal();
}
if(isDirty || newStatus->forceUpdate) {
DEBUG_MSG("Node status update: %d online, %d total\n", numOnline, numTotal);
LOG_DEBUG("Node status update: %d online, %d total\n", numOnline, numTotal);
onNewStatus.notifyObservers(this);
}
return 0;
Expand Down
Loading

0 comments on commit 69ff724

Please sign in to comment.