mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
multithreaded initial support
This commit is contained in:
parent
4ed5da0098
commit
046ac70071
@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <stdio.h>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
|
||||
/* Helper macro for logger utility class. */
|
||||
#define UPM_LOG(log_level) \
|
||||
@ -14,6 +16,8 @@
|
||||
<< __FUNCTION__ << " " \
|
||||
<< __LINE__ << ": "
|
||||
|
||||
#define LOG_FILE "/var/log/upm.log"
|
||||
|
||||
namespace upm {
|
||||
|
||||
enum UpmLogLevel {
|
||||
@ -38,6 +42,9 @@ namespace upm {
|
||||
virtual ~UPM_LOGGER();
|
||||
std::ostringstream& log(UpmLogLevel level = LOG_ERROR);
|
||||
static UpmLogLevel& LogLevel();
|
||||
|
||||
static std::ofstream logStream;
|
||||
static std::mutex logMutex;
|
||||
protected:
|
||||
std::ostringstream os;
|
||||
private:
|
||||
@ -56,6 +63,18 @@ namespace upm {
|
||||
|
||||
return logLevelNames[level];
|
||||
}
|
||||
|
||||
public:
|
||||
static void write(std::ostringstream& os)
|
||||
{
|
||||
|
||||
|
||||
std::lock_guard<std::mutex> lock(logMutex);
|
||||
|
||||
logStream.open(LOG_FILE, std::ios_base::app);
|
||||
logStream << os.str();
|
||||
logStream.flush();
|
||||
}
|
||||
};
|
||||
|
||||
UPM_LOGGER::UPM_LOGGER() {}
|
||||
@ -84,7 +103,7 @@ namespace upm {
|
||||
UPM_LOGGER::~UPM_LOGGER()
|
||||
{
|
||||
os << std::endl;
|
||||
fprintf(stderr, "%s", os.str().c_str());
|
||||
fflush(stderr);
|
||||
|
||||
write(os);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user