Fixing issues in new logging
This commit is contained in:
		
							parent
							
								
									2efa985a05
								
							
						
					
					
						commit
						b128732e56
					
				| 
						 | 
					@ -3,5 +3,8 @@
 | 
				
			||||||
    // for the documentation about the extensions.json format
 | 
					    // for the documentation about the extensions.json format
 | 
				
			||||||
    "recommendations": [
 | 
					    "recommendations": [
 | 
				
			||||||
        "platformio.platformio-ide"
 | 
					        "platformio.platformio-ide"
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    "unwantedRecommendations": [
 | 
				
			||||||
 | 
					        "ms-vscode.cpptools-extension-pack"
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@
 | 
				
			||||||
#include <stdint.h>
 | 
					#include <stdint.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include <utility>
 | 
					#include <utility>
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define LOG_INFO(...)                        \
 | 
					#define LOG_INFO(...)                        \
 | 
				
			||||||
| 
						 | 
					@ -48,14 +49,17 @@ public:
 | 
				
			||||||
    currentSize_ += sizeof(time);
 | 
					    currentSize_ += sizeof(time);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const auto spaceLeft = totalSize_ - currentSize_;
 | 
					    const auto spaceLeft = totalSize_ - currentSize_;
 | 
				
			||||||
 | 
					#pragma GCC diagnostic push
 | 
				
			||||||
 | 
					#pragma GCC diagnostic ignored "-Wformat-security"
 | 
				
			||||||
    auto charsWritten = snprintf(&data_[currentSize_], spaceLeft, formatStr,
 | 
					    auto charsWritten = snprintf(&data_[currentSize_], spaceLeft, formatStr,
 | 
				
			||||||
                                 std::forward<Args>(args)...);
 | 
					                                 std::forward<Args>(args)...);
 | 
				
			||||||
 | 
					#pragma GCC diagnostic pop
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                
 | 
					                                
 | 
				
			||||||
    //Serial.println(&data_[currentSize_]);
 | 
					    //Serial.println(&data_[currentSize_]);
 | 
				
			||||||
 | 
					    if(charsWritten > 0)
 | 
				
			||||||
    if (charsWritten < spaceLeft)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      currentSize_ += charsWritten;
 | 
					      currentSize_ += charsWritten + 1; // + 1 for trailing zero
 | 
				
			||||||
      return true;
 | 
					      return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
| 
						 | 
					@ -89,6 +93,9 @@ public:
 | 
				
			||||||
        current_position_ += sizeof(TimeT) + strlen(message()) + 1;
 | 
					        current_position_ += sizeof(TimeT) + strlen(message()) + 1;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      bool operator==(const iterator & o) const { return current_position_ == o.current_position_; }
 | 
				
			||||||
 | 
					      bool operator!=(const iterator & o) const { return current_position_ != o.current_position_; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private:
 | 
					    private:
 | 
				
			||||||
      const char * current_position_;
 | 
					      const char * current_position_;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,5 +40,6 @@ board_build.embed_txtfiles =
 | 
				
			||||||
[env:native]
 | 
					[env:native]
 | 
				
			||||||
platform = native
 | 
					platform = native
 | 
				
			||||||
test_ignore = test_embedded
 | 
					test_ignore = test_embedded
 | 
				
			||||||
build_flags = -g -DPLATFORM_NATIVE
 | 
					build_flags = -g -DPLATFORM_NATIVE  -std=c++17 -O0
 | 
				
			||||||
build_src_filter = +<*> -<firmware_main.cpp>
 | 
					build_src_filter = +<*> -<firmware_main.cpp> -<WifiManager.cpp> -<WifiAPI.cpp>
 | 
				
			||||||
 | 
					lib_compat_mode = off
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,23 @@
 | 
				
			||||||
#include "Logger.h"
 | 
					#include "Logger.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main()
 | 
					int main()
 | 
				
			||||||
{}
 | 
					{
 | 
				
			||||||
 | 
					  Logger::getInstance()->init();
 | 
				
			||||||
 | 
					  auto logger = Logger::getInstance();
 | 
				
			||||||
 | 
					  using namespace std::chrono_literals;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  LOG_INFO("Message1");
 | 
				
			||||||
 | 
					  LOG_INFO("Message %d", 5);
 | 
				
			||||||
 | 
					  std::this_thread::sleep_for(2000ms);
 | 
				
			||||||
 | 
					  LOG_INFO("Message %s", "3");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  for(auto it = logger->begin(); it != logger->end(); ++it)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					     std::cout << it.time_millis() << ": " << it.message() << std::endl;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
#include "Dtypes.h"
 | 
					#include "Dtypes.h"
 | 
				
			||||||
#include "MockSerial.h"
 | 
					#include "MockSerial.h"
 | 
				
			||||||
#include "MeasurementSession.h"
 | 
					#include "SimpleMeasurementSession.h"
 | 
				
			||||||
#include "MockStorage.h"
 | 
					#include "MockStorage.h"
 | 
				
			||||||
#include <unity.h>
 | 
					#include <unity.h>
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
| 
						 | 
					@ -120,8 +120,8 @@ void testSessionChunkSerialization()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void testSession() {
 | 
					void testSession() {
 | 
				
			||||||
    const uint32_t SESSION_SIZE = 128;
 | 
					    const uint32_t SESSION_SIZE = 1024;
 | 
				
			||||||
    typedef MeasurementSession<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
 | 
					    using MockSession = SimpleMeasurementSession<uint16_t, SESSION_SIZE>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const uint32_t startTime = 194842;
 | 
					    const uint32_t startTime = 194842;
 | 
				
			||||||
    const uint_t fillSize = SESSION_SIZE * 4 + 7;
 | 
					    const uint_t fillSize = SESSION_SIZE * 4 + 7;
 | 
				
			||||||
| 
						 | 
					@ -149,7 +149,7 @@ void testSession() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void testPartialSessionSerialization() {
 | 
					void testPartialSessionSerialization() {
 | 
				
			||||||
    const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t);
 | 
					    const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t);
 | 
				
			||||||
    typedef MeasurementSession<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
 | 
					    using MockSession = SimpleMeasurementSession<uint16_t, SESSION_SIZE>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const uint32_t startTime = 194842;
 | 
					    const uint32_t startTime = 194842;
 | 
				
			||||||
    const uint_t fillSize = 4937 + 81;
 | 
					    const uint_t fillSize = 4937 + 81;
 | 
				
			||||||
| 
						 | 
					@ -191,7 +191,7 @@ void testPartialSessionSerialization() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void testPartialSessionSerializationEmptyArray() {
 | 
					void testPartialSessionSerializationEmptyArray() {
 | 
				
			||||||
    const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t);
 | 
					    const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t);
 | 
				
			||||||
    typedef MeasurementSession<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
 | 
					    using MockSession = SimpleMeasurementSession<uint16_t, SESSION_SIZE>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const uint32_t startTime = 194842;
 | 
					    const uint32_t startTime = 194842;
 | 
				
			||||||
    const uint_t fillSize = 4937 + 81;
 | 
					    const uint_t fillSize = 4937 + 81;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue