mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-12 09:36:59 +00:00
[Cleanup] Reduce build size by compacting logs
This commit is contained in:
+4
-5
@@ -105,11 +105,10 @@ bool CPlugin_005(CPlugin::Function function, struct EventStruct *event, String&
|
||||
# ifndef BUILD_NO_DEBUG
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
|
||||
String log = F("MQTT : ");
|
||||
log += tmppubname;
|
||||
log += ' ';
|
||||
log += value;
|
||||
addLogMove(LOG_LEVEL_DEBUG, log);
|
||||
addLogMove(LOG_LEVEL_DEBUG,
|
||||
strformat(F("MQTT : %s %s"),
|
||||
tmppubname.c_str(),
|
||||
value.c_str()));
|
||||
}
|
||||
# endif // ifndef BUILD_NO_DEBUG
|
||||
|
||||
|
||||
+4
-5
@@ -929,11 +929,10 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String&
|
||||
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
|
||||
String log = F("C014 : Sent to ");
|
||||
log += tmppubname;
|
||||
log += ' ';
|
||||
log += value;
|
||||
addLogMove(LOG_LEVEL_DEBUG, log);
|
||||
addLogMove(LOG_LEVEL_DEBUG,
|
||||
strformat(F("C014 : Sent to %s %s"),
|
||||
tmppubname.c_str(),
|
||||
value.c_str()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+5
-12
@@ -198,18 +198,11 @@ boolean Plugin_007(uint8_t function, struct EventStruct *event, String& string)
|
||||
UserVar[event->BaseVarIndex + var] = Wire.read(); // now read actual value and store into Value var
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log;
|
||||
|
||||
if (log.reserve(40)) {
|
||||
log += F("PCF : Analog port: A");
|
||||
log += port - 1;
|
||||
log += F(" value ");
|
||||
log += var + 1;
|
||||
log += ':';
|
||||
log += ' ';
|
||||
log += formatUserVarNoCheck(event->TaskIndex, var);
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
}
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("PCF : Analog port: A%d value %d: %s"),
|
||||
port - 1,
|
||||
var + 1,
|
||||
formatUserVarNoCheck(event->TaskIndex, var).c_str()));
|
||||
}
|
||||
success = true;
|
||||
}
|
||||
|
||||
+12
-15
@@ -463,13 +463,11 @@ void Plugin_055_AddStringFIFO(const String& param)
|
||||
|
||||
void Plugin_055_WriteChime(const String& name, const String& tokens)
|
||||
{
|
||||
String fileName = F("chime_");
|
||||
fileName += name;
|
||||
fileName += F(".txt");
|
||||
const String fileName = strformat(F("chime_%s.txt"), name.c_str());
|
||||
|
||||
String log = F("Chime: write ");
|
||||
log += fileName;
|
||||
log += ' ';
|
||||
String log;
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO))
|
||||
log = strformat(F("Chime: write %s "), fileName.c_str());
|
||||
|
||||
fs::File f = tryOpenFile(fileName, "w");
|
||||
if (f)
|
||||
@@ -477,7 +475,8 @@ void Plugin_055_WriteChime(const String& name, const String& tokens)
|
||||
f.print(tokens);
|
||||
f.close();
|
||||
//flashCount();
|
||||
log += tokens;
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO))
|
||||
log += tokens;
|
||||
}
|
||||
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
@@ -485,13 +484,11 @@ void Plugin_055_WriteChime(const String& name, const String& tokens)
|
||||
|
||||
uint8_t Plugin_055_ReadChime(const String& name, String& tokens)
|
||||
{
|
||||
String fileName = F("chime_");
|
||||
fileName += name;
|
||||
fileName += F(".txt");
|
||||
const String fileName = strformat(F("chime_%s.txt"), name.c_str());
|
||||
|
||||
String log = F("Chime: read ");
|
||||
log += fileName;
|
||||
log += ' ';
|
||||
String log;
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO))
|
||||
log = strformat(F("Chime: read %s "), fileName.c_str());
|
||||
|
||||
tokens = String();
|
||||
fs::File f = tryOpenFile(fileName, "r");
|
||||
@@ -505,8 +502,8 @@ uint8_t Plugin_055_ReadChime(const String& name, String& tokens)
|
||||
tokens += c;
|
||||
}
|
||||
f.close();
|
||||
|
||||
log += tokens;
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO))
|
||||
log += tokens;
|
||||
}
|
||||
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
|
||||
@@ -651,7 +651,7 @@ bool PluginCall(uint8_t Function, struct EventStruct *event, String& str)
|
||||
clearPluginTaskData(taskIndex); // Make sure any task data is actually cleared.
|
||||
if (PluginCallForTask(taskIndex, PLUGIN_INIT, &TempEvent, str, event) &&
|
||||
loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLogMove(LOG_LEVEL_INFO, strformat(F("INIT : Started Priority task %d, [%s] %s"),
|
||||
addLog(LOG_LEVEL_INFO, strformat(F("INIT : Started Priority task %d, [%s] %s"),
|
||||
taskIndex + 1,
|
||||
getTaskDeviceName(taskIndex).c_str(),
|
||||
getPluginNameFromDeviceIndex(getDeviceIndex_from_TaskIndex(taskIndex)).c_str()));
|
||||
|
||||
@@ -277,14 +277,18 @@ bool BuildFixes()
|
||||
|
||||
if (Settings.Build < 20101)
|
||||
{
|
||||
#ifdef LIMIT_BUILD_SIZE
|
||||
serialPrintln(F("Fix reset Pin"));
|
||||
#endif
|
||||
Settings.Pin_Reset = -1;
|
||||
}
|
||||
|
||||
if (Settings.Build < 20102) {
|
||||
// Settings were 'mangled' by using older version
|
||||
// Have to patch settings to make sure no bogus data is being used.
|
||||
#ifdef LIMIT_BUILD_SIZE
|
||||
serialPrintln(F("Fix settings with uninitalized data or corrupted by switching between versions"));
|
||||
#endif
|
||||
Settings.UseRTOSMultitasking = false;
|
||||
Settings.Pin_Reset = -1;
|
||||
Settings.SyslogFacility = DEFAULT_SYSLOG_FACILITY;
|
||||
|
||||
@@ -303,9 +303,9 @@ unsigned long ESPEasy_time::now() {
|
||||
calcSunRiseAndSet();
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String log = F("Local time: ");
|
||||
log += getDateTimeString('-', ':', ' ');
|
||||
addLogMove(LOG_LEVEL_INFO, log);
|
||||
addLog(LOG_LEVEL_INFO, strformat(
|
||||
F("Local time: %s"),
|
||||
getDateTimeString('-', ':', ' ').c_str()));
|
||||
}
|
||||
{
|
||||
// Notify plugins the time has been set.
|
||||
@@ -388,8 +388,8 @@ bool ESPEasy_time::getNtpTime(double& unixTime_d)
|
||||
nextSyncTime = sysTime + HwRandom(20, 60);
|
||||
} else {
|
||||
// Have to do a lookup each time, since the NTP pool always returns another IP
|
||||
String ntpServerName = String(HwRandom(0, 3));
|
||||
ntpServerName += F(".pool.ntp.org");
|
||||
const String ntpServerName = strformat(
|
||||
F("%d.pool.ntp.org"), HwRandom(0, 3));
|
||||
resolveHostByName(ntpServerName.c_str(), timeServerIP);
|
||||
log += ntpServerName;
|
||||
|
||||
@@ -416,7 +416,7 @@ bool ESPEasy_time::getNtpTime(double& unixTime_d)
|
||||
}
|
||||
|
||||
const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
|
||||
uint8_t packetBuffer[NTP_PACKET_SIZE]; // buffer to hold incoming & outgoing packets
|
||||
uint8_t packetBuffer[NTP_PACKET_SIZE]{}; // buffer to hold incoming & outgoing packets
|
||||
|
||||
log += F(" queried");
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
@@ -425,7 +425,6 @@ bool ESPEasy_time::getNtpTime(double& unixTime_d)
|
||||
|
||||
while (udp.parsePacket() > 0) { // discard any previously received packets
|
||||
}
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
packetBuffer[1] = 0; // Stratum, or type of clock
|
||||
packetBuffer[2] = 6; // Polling Interval
|
||||
@@ -460,10 +459,9 @@ bool ESPEasy_time::getNtpTime(double& unixTime_d)
|
||||
// Leap-Indicator: unknown (clock unsynchronized)
|
||||
// See: https://github.com/letscontrolit/ESPEasy/issues/2886#issuecomment-586656384
|
||||
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
|
||||
String log = F("NTP : NTP host (");
|
||||
log += formatIP(timeServerIP);
|
||||
log += F(") unsynchronized");
|
||||
addLogMove(LOG_LEVEL_ERROR, log);
|
||||
addLog(LOG_LEVEL_ERROR, strformat(
|
||||
F("NTP : NTP host (%s) unsynchronized"),
|
||||
formatIP(timeServerIP).c_str()));
|
||||
}
|
||||
|
||||
if (!useNTPpool) {
|
||||
|
||||
@@ -1747,7 +1747,7 @@ bool downloadFile(const String& url, String file_save, const String& user, const
|
||||
client.stop();
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLogMove(LOG_LEVEL_INFO, strformat(F("downloadFile: %s Success"), file_save.c_str()));
|
||||
addLog(LOG_LEVEL_INFO, strformat(F("downloadFile: %s Success"), file_save.c_str()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1846,13 +1846,12 @@ bool downloadFirmware(const String& url, String& file_save, String& user, String
|
||||
client.stop();
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
addLogMove(LOG_LEVEL_INFO, strformat(F("downloadFile: %s Success"), file_save.c_str()));
|
||||
addLog(LOG_LEVEL_INFO, strformat(F("downloadFile: %s Success"), file_save.c_str()));
|
||||
}
|
||||
|
||||
if (Update.end()) {
|
||||
if (Settings.UseRules) {
|
||||
String event = concat(F("ProvisionFirmware#success="), file_save);
|
||||
eventQueue.addMove(std::move(event));
|
||||
eventQueue.addMove(concat(F("ProvisionFirmware#success="), file_save));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -151,14 +151,11 @@ void runOncePerSecond()
|
||||
{
|
||||
// FIXME TD-er: What to do when the system time is not (yet) present?
|
||||
if (node_time.systemTimePresent()) {
|
||||
String event;
|
||||
event.reserve(21);
|
||||
event += F("Clock#Time=");
|
||||
event += node_time.weekday_str();
|
||||
event += ',';
|
||||
event += node_time.getTimeString(':', false);
|
||||
|
||||
// TD-er: Do not add to the eventQueue, but execute right now.
|
||||
const String event = strformat(
|
||||
F("Clock#Time=%s,%s"),
|
||||
node_time.weekday_str().c_str(),
|
||||
node_time.getTimeString(':', false).c_str());
|
||||
rulesProcessing(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,13 +397,11 @@ String doFormatUserVar(struct EventStruct *event, uint8_t rel_index, bool mustCh
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_ERROR)) {
|
||||
String log = F("No sensor value for TaskIndex: ");
|
||||
log += event->TaskIndex + 1;
|
||||
log += F(" varnumber: ");
|
||||
log += rel_index + 1;
|
||||
log += F(" type: ");
|
||||
log += getSensorTypeLabel(sensorType);
|
||||
addLogMove(LOG_LEVEL_ERROR, log);
|
||||
addLogMove(LOG_LEVEL_ERROR, strformat(
|
||||
F("No sensor value for TaskIndex: %d varnumber: %d type: %s"),
|
||||
event->TaskIndex + 1,
|
||||
rel_index + 1,
|
||||
String(getSensorTypeLabel(sensorType)).c_str()));
|
||||
}
|
||||
#endif // ifndef BUILD_NO_DEBUG
|
||||
return EMPTY_STRING;
|
||||
@@ -424,14 +422,13 @@ String doFormatUserVar(struct EventStruct *event, uint8_t rel_index, bool mustCh
|
||||
#ifndef BUILD_NO_DEBUG
|
||||
|
||||
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
|
||||
String log = F("Invalid float value for TaskIndex: ");
|
||||
log += event->TaskIndex;
|
||||
log += F(" varnumber: ");
|
||||
log += rel_index;
|
||||
addLogMove(LOG_LEVEL_DEBUG, log);
|
||||
addLogMove(LOG_LEVEL_DEBUG, strformat(
|
||||
F("Invalid float value for TaskIndex: %d varnumber: %d"),
|
||||
event->TaskIndex + 1,
|
||||
rel_index + 1));
|
||||
}
|
||||
#endif // ifndef BUILD_NO_DEBUG
|
||||
const float f = 0.0f;
|
||||
const float f{};
|
||||
return toString(f, nrDecimals);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user