mirror of
				https://github.com/eclipse/upm.git
				synced 2025-11-04 09:05:34 +03:00 
			
		
		
		
	example for logger class + minor improvements
This commit is contained in:
		
				
					committed by
					
						
						Stefan Andritoiu
					
				
			
			
				
	
			
			
			
						parent
						
							046ac70071
						
					
				
				
					commit
					43ecacfce7
				
			@@ -1,16 +1,34 @@
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "upm_logger.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace upm;
 | 
			
		||||
 | 
			
		||||
void print()
 | 
			
		||||
{
 | 
			
		||||
  UPM_LOG(LOG_DEBUG) << "Thread " << std::this_thread::get_id() << ": running loop with 3 iterations";
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < 4; ++i) {
 | 
			
		||||
    UPM_LOG(LOG_DEBUG) << std::this_thread::get_id() << ": i = " << i;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main()
 | 
			
		||||
{
 | 
			
		||||
  std::vector<std::thread> threads;
 | 
			
		||||
 | 
			
		||||
  UPM_LOGGER::LogLevel() = LOG_INFO;
 | 
			
		||||
 | 
			
		||||
  UPM_LOG(LOG_WARNING) << "a loop with 4 iterations";
 | 
			
		||||
  UPM_LOG(LOG_WARNING) << "Testing the upm logger";
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < 4; ++i) {
 | 
			
		||||
    UPM_LOG(LOG_DEBUG) << "i = " << i;
 | 
			
		||||
  // Launching 5 threads
 | 
			
		||||
  for (int i = 0; i < 5; ++i) {
 | 
			
		||||
    threads.push_back(std::thread(print));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (auto& thread : threads) {
 | 
			
		||||
    thread.join();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user