Fixing issues in new logging
This commit is contained in:
		
							parent
							
								
									2efa985a05
								
							
						
					
					
						commit
						b128732e56
					
				| 
						 | 
				
			
			@ -1,7 +1,10 @@
 | 
			
		|||
{
 | 
			
		||||
    // See http://go.microsoft.com/fwlink/?LinkId=827846
 | 
			
		||||
    // for the documentation about the extensions.json format
 | 
			
		||||
    "recommendations": [
 | 
			
		||||
        "platformio.platformio-ide"
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
{
 | 
			
		||||
    // See http://go.microsoft.com/fwlink/?LinkId=827846
 | 
			
		||||
    // for the documentation about the extensions.json format
 | 
			
		||||
    "recommendations": [
 | 
			
		||||
        "platformio.platformio-ide"
 | 
			
		||||
    ],
 | 
			
		||||
    "unwantedRecommendations": [
 | 
			
		||||
        "ms-vscode.cpptools-extension-pack"
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
 | 
			
		||||
constexpr size_t LOG_SIZE = 1024 * 1024 * 2;
 | 
			
		||||
 | 
			
		||||
static Logger *theLogger = nullptr;
 | 
			
		||||
static Logger * theLogger = nullptr;
 | 
			
		||||
 | 
			
		||||
Logger *Logger::getInstance()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@
 | 
			
		|||
#include <stdint.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <utility>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define LOG_INFO(...)                        \
 | 
			
		||||
| 
						 | 
				
			
			@ -48,14 +49,17 @@ public:
 | 
			
		|||
    currentSize_ += sizeof(time);
 | 
			
		||||
 | 
			
		||||
    const auto spaceLeft = totalSize_ - currentSize_;
 | 
			
		||||
#pragma GCC diagnostic push
 | 
			
		||||
#pragma GCC diagnostic ignored "-Wformat-security"
 | 
			
		||||
    auto charsWritten = snprintf(&data_[currentSize_], spaceLeft, formatStr,
 | 
			
		||||
                                 std::forward<Args>(args)...);
 | 
			
		||||
#pragma GCC diagnostic pop
 | 
			
		||||
 | 
			
		||||
                                
 | 
			
		||||
    //Serial.println(&data_[currentSize_]);
 | 
			
		||||
 | 
			
		||||
    if (charsWritten < spaceLeft)
 | 
			
		||||
    if(charsWritten > 0)
 | 
			
		||||
    {
 | 
			
		||||
      currentSize_ += charsWritten;
 | 
			
		||||
      currentSize_ += charsWritten + 1; // + 1 for trailing zero
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +93,9 @@ public:
 | 
			
		|||
        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:
 | 
			
		||||
      const char * current_position_;
 | 
			
		||||
  };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,5 +40,6 @@ board_build.embed_txtfiles =
 | 
			
		|||
[env:native]
 | 
			
		||||
platform = native
 | 
			
		||||
test_ignore = test_embedded
 | 
			
		||||
build_flags = -g -DPLATFORM_NATIVE
 | 
			
		||||
build_src_filter = +<*> -<firmware_main.cpp>
 | 
			
		||||
build_flags = -g -DPLATFORM_NATIVE  -std=c++17 -O0
 | 
			
		||||
build_src_filter = +<*> -<firmware_main.cpp> -<WifiManager.cpp> -<WifiAPI.cpp>
 | 
			
		||||
lib_compat_mode = off
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,23 @@
 | 
			
		|||
#include "Logger.h"
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <chrono>
 | 
			
		||||
#include <thread>
 | 
			
		||||
 | 
			
		||||
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 "MockSerial.h"
 | 
			
		||||
#include "MeasurementSession.h"
 | 
			
		||||
#include "SimpleMeasurementSession.h"
 | 
			
		||||
#include "MockStorage.h"
 | 
			
		||||
#include <unity.h>
 | 
			
		||||
#include <vector>
 | 
			
		||||
| 
						 | 
				
			
			@ -120,8 +120,8 @@ void testSessionChunkSerialization()
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
void testSession() {
 | 
			
		||||
    const uint32_t SESSION_SIZE = 128;
 | 
			
		||||
    typedef MeasurementSession<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
 | 
			
		||||
    const uint32_t SESSION_SIZE = 1024;
 | 
			
		||||
    using MockSession = SimpleMeasurementSession<uint16_t, SESSION_SIZE>;
 | 
			
		||||
 | 
			
		||||
    const uint32_t startTime = 194842;
 | 
			
		||||
    const uint_t fillSize = SESSION_SIZE * 4 + 7;
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +149,7 @@ void testSession() {
 | 
			
		|||
 | 
			
		||||
void testPartialSessionSerialization() {
 | 
			
		||||
    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 uint_t fillSize = 4937 + 81;
 | 
			
		||||
| 
						 | 
				
			
			@ -191,7 +191,7 @@ void testPartialSessionSerialization() {
 | 
			
		|||
 | 
			
		||||
void testPartialSessionSerializationEmptyArray() {
 | 
			
		||||
    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 uint_t fillSize = 4937 + 81;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue