فهرست منبع

Merge pull request #1231 from jomjol/improve-logfile-logging

Improve logging to logfile
jomjol 3 سال پیش
والد
کامیت
99849063d9

+ 0 - 4
code/components/jomjol_controlcamera/ClassControllCamera.cpp

@@ -263,7 +263,6 @@ void CCamera::EnableAutoExposure(int flashdauer)
         ESP_LOGE(TAGCAMERACLASS, "Camera Capture Failed");
         LEDOnOff(false);
         LightOnOff(false);
-        LogFile.SwitchOnOff(true);
         LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (Procedure 'EnableAutoExposure') --> Reboot! "
                 "Check that your camera module is working and connected properly.");
         //doReboot();
@@ -315,7 +314,6 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
         LEDOnOff(false);
         LightOnOff(false);
 
-        LogFile.SwitchOnOff(true);
         LogFile.WriteToFile(ESP_LOG_ERROR, "Camera is not working anymore (CCamera::CaptureToBasisImage) - most probably caused by a hardware problem (instablility, ...). "
                 "System will reboot.");
         doReboot();
@@ -328,7 +326,6 @@ esp_err_t CCamera::CaptureToBasisImage(CImageBasis *_Image, int delay)
     if (!zwischenspeicher)
     {
         ESP_LOGE(TAGCAMERACLASS, "Insufficient memory space for image in function CaptureToBasisImage()");
-        LogFile.SwitchOnOff(true);
         LogFile.WriteToFile(ESP_LOG_ERROR, "Insufficient memory space for image in function CaptureToBasisImage()");
     }
     for (int i = 0; i < _size; ++i)
@@ -413,7 +410,6 @@ esp_err_t CCamera::CaptureToFile(std::string nm, int delay)
         ESP_LOGE(TAGCAMERACLASS, "CaptureToFile: Camera Capture Failed");
         LEDOnOff(false);
         LightOnOff(false);
-        LogFile.SwitchOnOff(true);
         LogFile.WriteToFile(ESP_LOG_ERROR, "Camera Capture Failed (CCamera::CaptureToFile) --> Reboot! "
                 "Check that your camera module is working and connected properly.");
         //doReboot();

+ 0 - 1
code/components/jomjol_fileserver_ota/server_ota.cpp

@@ -492,7 +492,6 @@ void task_reboot(void *pvParameter)
 }
 
 void doReboot(){
-    LogFile.SwitchOnOff(true);
     LogFile.WriteToFile(ESP_LOG_INFO, "Reboot triggered by Software (5s).");
     LogFile.WriteToFile(ESP_LOG_WARN, "Reboot in 5sec");
     xTaskCreate(&task_reboot, "reboot", configMINIMAL_STACK_SIZE * 64, NULL, 10, NULL);

+ 1 - 3
code/components/jomjol_flowcontroll/ClassFlowControll.cpp

@@ -305,7 +305,6 @@ bool ClassFlowControll::doFlow(string time)
             if (i) i -= 1;    // vorheriger Schritt muss wiederholt werden (vermutlich Bilder aufnehmen)
             result = false;
             if (repeat > 5) {
-                LogFile.SwitchOnOff(true);
                 LogFile.WriteToFile(ESP_LOG_ERROR, "Wiederholung 5x nicht erfolgreich --> reboot");
                 doReboot();
                 // Schritt wurde 5x wiederholt --> reboot
@@ -493,8 +492,7 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
             {
                 // reboot notwendig damit die neue wlan.ini auch benutzt wird !!!
                 fclose(pfile);
-                LogFile.SwitchOnOff(true);
-                LogFile.WriteToFile(ESP_LOG_WARN, "Rebooting to activate new HOSTNAME...");
+                LogFile.WriteToFile(ESP_LOG_ERROR, "Rebooting to activate new HOSTNAME...");
                 esp_restart();
                 hard_restart();                   
                 doReboot();

+ 0 - 1
code/components/jomjol_image_proc/CImageBasis.cpp

@@ -362,7 +362,6 @@ void CImageBasis::LoadFromMemory(stbi_uc *_buffer, int len)
     ESP_LOGD(TAG, "Image loaded from memory: %d, %d, %d", width, height, channels);
     if ((width * height * channels) == 0)
     {
-        LogFile.SwitchOnOff(true);
         LogFile.WriteToFile(ESP_LOG_ERROR, "Image with size 0 loaded --> reboot to be done! "
                 "Check that your camera module is working and connected properly.");
 

+ 1 - 1
code/components/jomjol_logfile/ClassLogFile.cpp

@@ -120,7 +120,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
     std::string zwtime;
     std::string logline = "";
 
-    if (!doLogFile){
+    if (!doLogFile && level != ESP_LOG_ERROR){ // Only write to file if logfile is enabled or its an error message
         return;
     }
 

+ 1 - 2
code/components/jomjol_mqtt/interface_mqtt.cpp

@@ -11,7 +11,6 @@ static const char *TAG_INTERFACEMQTT = "interface_mqtt";
 
 std::map<std::string, std::function<void()>>* connectFunktionMap = NULL;  
 std::map<std::string, std::function<bool(std::string, char*, int)>>* subscribeFunktionMap = NULL;  
-bool debugdetail = true;
 
 // #define CONFIG_BROKER_URL "mqtt://192.168.178.43:1883"
 
@@ -31,7 +30,7 @@ bool MQTTPublish(std::string _key, std::string _content, int retained_flag){
         return false;
     }
     zw = "MQTT - sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content;
-    if (debugdetail) LogFile.WriteToFile(ESP_LOG_INFO, zw);
+    LogFile.WriteToFile(ESP_LOG_INFO, zw);
     return true;
 }
 

+ 0 - 6
code/main/main.cpp

@@ -219,7 +219,6 @@ extern "C" void app_main(void)
     LogFile.WriteToFile(ESP_LOG_INFO, "=============================================================================================");
     LogFile.WriteToFile(ESP_LOG_INFO, versionFormated);
     LogFile.WriteToFile(ESP_LOG_INFO, "Reset reason: " + getResetReason());
-    LogFile.SwitchOnOff(false);
 
     std::string zw = gettimestring("%Y%m%d-%H%M%S");
     ESP_LOGD(TAGMAIN, "time %s", zw.c_str());
@@ -229,20 +228,15 @@ extern "C" void app_main(void)
     {
         std::string _zws = "Not enough PSRAM available. Expected 4.194.304 MByte - available: " + std::to_string(_hsize);
         _zws = _zws + "\nEither not initialzed, too small (2MByte only) or not present at all. Firmware cannot start!!";
-        LogFile.SwitchOnOff(true);
         LogFile.WriteToFile(ESP_LOG_ERROR, _zws);
-        LogFile.SwitchOnOff(false);
     } else {
         if (cam != ESP_OK) {
-                LogFile.SwitchOnOff(true);
                 LogFile.WriteToFile(ESP_LOG_ERROR, "Failed to initialize camera module. "
                         "Check that your camera module is working and connected properly.");
-                LogFile.SwitchOnOff(false);
         } else {
 // Test Camera            
             camera_fb_t * fb = esp_camera_fb_get();
             if (!fb) {
-                LogFile.SwitchOnOff(true);
                 LogFile.WriteToFile(ESP_LOG_ERROR, "Camera cannot be initialzed. "
                         "System will reboot.");
                 doReboot();