From 0fa32d9b971ad581f776fb662dceb743c5519ea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 10 Apr 2024 13:18:23 +0200 Subject: [PATCH] removed 'module' from log --- lib/patrix/Patrix.cpp | 2 +- lib/patrix/console.cpp | 36 ++++++++++++++++++------------------ lib/patrix/log.cpp | 18 +++++++++--------- lib/patrix/log.h | 6 +++--- lib/patrix/mqtt.cpp | 14 +++++++------- lib/patrix/sensors/Dallas.h | 8 ++++---- lib/patrix/wifi.cpp | 18 +++++++++--------- 7 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/patrix/Patrix.cpp b/lib/patrix/Patrix.cpp index 82c735f..5fc1f8e 100644 --- a/lib/patrix/Patrix.cpp +++ b/lib/patrix/Patrix.cpp @@ -9,7 +9,7 @@ void setup() { delay(500); Serial.begin(115200); - info("MAIN", "Startup..."); + info("Startup..."); mqttSetup(); wifiSetup(); patrixSetup(); diff --git a/lib/patrix/console.cpp b/lib/patrix/console.cpp index 36f8bd2..770f7f2 100644 --- a/lib/patrix/console.cpp +++ b/lib/patrix/console.cpp @@ -17,7 +17,7 @@ void consoleLoop() { if (symbol == '\n' || symbol == '\r') { if (*consoleBuffer != 0) { Serial.print('\n'); - info("CONSOLE", "> %s", consoleBuffer); + info("CONSOLE > %s", consoleBuffer); consoleHandle(consoleBuffer); consoleBufferW = consoleBuffer; *consoleBufferW = 0; @@ -45,34 +45,34 @@ void consoleLoop() { void consoleHandle(const char *cmd) { if (strcmp(cmd, "help") == 0) { - info("CONSOLE", "help : print this help"); - info("CONSOLE", "net : print network info"); - info("CONSOLE", "reboot : reboot system"); - info("CONSOLE", "wifi : reconnect wifi"); - info("CONSOLE", "mqtt : reconnect mqtt"); - info("CONSOLE", "debug : toggle debug log"); + info("help : print this help"); + info("net : print network info"); + info("reboot : reboot system"); + info("wifi : reconnect wifi"); + info("mqtt : reconnect mqtt"); + info("debug : toggle debug log"); } else if (strcmp(cmd, "net") == 0) { - info("CONSOLE", "MAC: %17s", WiFi.macAddress().c_str()); - info("CONSOLE", "IP: %17s", WiFi.localIP().toString().c_str()); - info("CONSOLE", "Gateway: %17s", WiFi.gatewayIP().toString().c_str()); - info("CONSOLE", "SSID: %17s", WiFi.SSID().c_str()); - info("CONSOLE", "BSSID: %17s", WiFi.BSSIDstr().c_str()); - info("CONSOLE", "RSSI: %17d", WiFi.RSSI()); + info("MAC: %17s", WiFi.macAddress().c_str()); + info("IP: %17s", WiFi.localIP().toString().c_str()); + info("Gateway: %17s", WiFi.gatewayIP().toString().c_str()); + info("SSID: %17s", WiFi.SSID().c_str()); + info("BSSID: %17s", WiFi.BSSIDstr().c_str()); + info("RSSI: %17d", WiFi.RSSI()); } else if (strcmp(cmd, "reboot") == 0) { - info("CONSOLE", "Rebooting..."); + info("Rebooting..."); delay(500); yield(); ESP.restart(); } else if (strcmp(cmd, "wifi") == 0) { - info("CONSOLE", "Reconnecting WiFi..."); + info("Reconnecting WiFi..."); wifiConnect(); } else if (strcmp(cmd, "mqtt") == 0) { - info("CONSOLE", "Reconnecting MQTT..."); + info("Reconnecting MQTT..."); mqttDisconnect(); } else if (strcmp(cmd, "debug") == 0) { setDebugEnabled(!isDebugEnabled()); - info("CONSOLE", "DEBUG: %s", isDebugEnabled() ? "ON" : "OFF"); + info("DEBUG: %s", isDebugEnabled() ? "ON" : "OFF"); } else { - info("CONSOLE", "Unknown command: %s", cmd); + info("Unknown command: %s", cmd); } } diff --git a/lib/patrix/log.cpp b/lib/patrix/log.cpp index dbaf43e..6de4a63 100644 --- a/lib/patrix/log.cpp +++ b/lib/patrix/log.cpp @@ -12,12 +12,12 @@ void getDateTime(char *buffer, size_t size) { strftime(buffer, size, "%Y-%m-%d %H:%M:%S %z", &time); } -void log(const char *level, const char *module, const char *format, va_list vl) { +void log(const char *level, const char *format, va_list vl) { char datetime[26]; getDateTime(datetime, sizeof datetime); - char header[45]; - snprintf(header, sizeof header, " | %-5s | %-10s | ", level, module); + char header[20]; + snprintf(header, sizeof header, " | %-5s | ", level); char message[500]; vsnprintf(message, sizeof message, format, vl); @@ -30,27 +30,27 @@ void log(const char *level, const char *module, const char *format, va_list vl) mqttPublishLog(datetime, header, message); } -void debug(const char *module, const char *format, ...) { +void debug(const char *format, ...) { if (!debugEnabled) { return; } va_list vl; va_start(vl, format); - log("DEBUG", module, format, vl); + log("DEBUG", format, vl); va_end(vl); } -void info(const char *module, const char *format, ...) { +void info(const char *format, ...) { va_list vl; va_start(vl, format); - log("INFO", module, format, vl); + log("INFO", format, vl); va_end(vl); } -void error(const char *module, const char *format, ...) { +void error(const char *format, ...) { va_list vl; va_start(vl, format); - log("ERROR", module, format, vl); + log("ERROR", format, vl); va_end(vl); } diff --git a/lib/patrix/log.h b/lib/patrix/log.h index 2b00442..fefcbd7 100644 --- a/lib/patrix/log.h +++ b/lib/patrix/log.h @@ -1,11 +1,11 @@ #ifndef SENSOR3_LOG_H #define SENSOR3_LOG_H -void debug(const char *module, const char *format, ...); +void debug(const char *format, ...); -void info(const char *module, const char *format, ...); +void info(const char *format, ...); -void error(const char *module, const char *format, ...); +void error(const char *format, ...); void setDebugEnabled(bool enabled); diff --git a/lib/patrix/mqtt.cpp b/lib/patrix/mqtt.cpp index 8cf71f6..937b10f 100644 --- a/lib/patrix/mqtt.cpp +++ b/lib/patrix/mqtt.cpp @@ -32,7 +32,7 @@ void mqttSetup() { void mqttDisconnect() { if (mqttConnected) { - info("MQTT", "Disconnecting"); + info("MQTT disconnecting"); mqtt.disconnect(); mqttConnected = false; } @@ -42,34 +42,34 @@ void mqttLoop() { const bool connected = mqtt.loop(); if (mqttConnected != connected) { if (!connected) { - error("MQTT", "DISCONNECTED"); + error("MQTT DISCONNECTED"); } mqttConnected = connected; } if (isWiFiConnected() && isTimeSet() && !connected && (mqttLastConnectTry == 0 || millis() - mqttLastConnectTry > CONNECT_TIMEOUT_MILLISECONDS)) { - error("MQTT", "Connecting MQTT host: %s", MQTT_HOST); + error("MQTT connecting MQTT host: %s", MQTT_HOST); mqttLastConnectTry = millis(); mqtt.setServer(MQTT_HOST, 1883); if (!mqtt.connect(HOSTNAME, logTopic, 0, false, "MQTT disconnected")) { - error("MQTT", "FAILED TO CONNECT"); + error("MQTT FAILED TO CONNECT"); return; } - info("MQTT", "CONNECTED"); + info("MQTT CONNECTED"); mqtt.setKeepAlive(10); mqtt.setBufferSize(512); // mqtt.subscribe(cmdTopic); mqtt.setCallback([](const char *topic, const uint8_t *bytes, const unsigned int length) { char content[64]; if (length > sizeof content - 1) { - error("MQTT", "MQTT RECEIVE BUFFER OVERFLOW"); + error("MQTT RECEIVE BUFFER OVERFLOW"); return; } memcpy(content, bytes, length); content[length] = 0; if (strcmp(topic, cmdTopic) == 0) { - info("MQTT", "CMD > %s", content); + info("MQTT CMD > %s", content); consoleHandle(content); } }); diff --git a/lib/patrix/sensors/Dallas.h b/lib/patrix/sensors/Dallas.h index 0390d1a..7e93e1a 100644 --- a/lib/patrix/sensors/Dallas.h +++ b/lib/patrix/sensors/Dallas.h @@ -43,20 +43,20 @@ public: first = false; uint8_t count = sensors.getDeviceCount(); if (count == 0) { - error("DALLAS", "No devices found!"); + error("No devices found!"); } else { - debug("DALLAS", "Found %d devices:", count); + debug("Found %d devices:", count); uint64_t address; for (int index = 0; index < count; ++index) { sensors.getAddress((uint8_t *) &address, index); - debug("DALLAS", " - 0x%016llX = %5.1f C", address, sensors.getTempC((uint8_t *) &address)); + debug(" - 0x%016llX = %5.1f C", address, sensors.getTempC((uint8_t *) &address)); } } } converting = false; converted = true; } else if (millis() - lastMillis > DALLAS_TIMEOUT_MILLISECONDS) { - error("DALLAS", "Timeout!"); + error("Timeout!"); converting = false; converted = false; } diff --git a/lib/patrix/wifi.cpp b/lib/patrix/wifi.cpp index e5a6dc5..bed7cdb 100644 --- a/lib/patrix/wifi.cpp +++ b/lib/patrix/wifi.cpp @@ -55,7 +55,7 @@ void wifiConnect() { WiFi.setAutoReconnect(false); yield(); - info("WIFI", "Connecting: %s", WIFI_SSID); + info("WIFI connecting: %s", WIFI_SSID); WiFiClass::hostname(HOSTNAME); yield(); @@ -66,18 +66,18 @@ void wifiConnect() { void otaSetup() { ArduinoOTA.onStart([] { - info("OTA", "OTA start..."); + info("OTA start..."); otaLastLogStep = 0; }); ArduinoOTA.onProgress([](unsigned int received, unsigned int total) { uint8_t currentStep = 20 * received / total; if (otaLastLogStep != currentStep) { - info("OTA", "OTA Progress: %3d%%", currentStep * 5); + info("OTA Progress: %3d%%", currentStep * 5); otaLastLogStep = currentStep; } }); ArduinoOTA.onEnd([] { - info("OTA", "OTA Complete!"); + info("OTA Complete!"); }); ArduinoOTA.onError([](ota_error_t e) { const char *name; @@ -101,7 +101,7 @@ void otaSetup() { name = "[???]"; break; } - error("OTA", name); + error(name); }); } @@ -132,7 +132,7 @@ void wifiLoop() { if (!timeSet) { preTimeOffset = epochSeconds; } else { - info("NTP", "Time set!"); + info("Got time via NTP"); } } @@ -140,7 +140,7 @@ void wifiLoop() { if (wifiConnected) { if (!hasIp) { wifiConnected = false; - info("WIFI", "WiFi disconnected!"); + info("WiFi disconnected!"); wifiConnect(); } else { ArduinoOTA.handle(); @@ -148,11 +148,11 @@ void wifiLoop() { } else { if (hasIp) { wifiConnected = true; - info("WIFI", "WiFi connected: ip=%s", WiFi.localIP().toString().c_str()); + info("WiFi connected: ip=%s", WiFi.localIP().toString().c_str()); ArduinoOTA.begin(); configTime(TIMEZONE_OFFSET, DST_OFFSET, WiFi.gatewayIP().toString().c_str(), NTP_SERVER); } else if (millis() - wifiLastConnectTry > WIFI_TIMEOUT_MS) { - info("WIFI", "WiFi timeout!"); + info("WiFi timeout!"); wifiConnect(); } }