+ logging with multiple arguments

This commit is contained in:
Julian Hinxlage 2019-11-12 18:09:50 +01:00
parent 051f366411
commit 0ae6f39f86
4 changed files with 26 additions and 12 deletions

View File

@ -57,16 +57,9 @@ int semaphoreOperation(int op) {
} }
void writeSharedMemory(char *data, int size, int offset) { void writeSharedMemory(char *data, int size, int offset) {
int shmId = shmget(impl.sharedMemoryKey, 0, 0); // dont init just get the ID if already existing. lockSharedMemory();
if (shmId >= 0) { memcpy(getSharedMemory() + offset, data, size);
std::cout << "writing" << std::endl; unlockSharedMemory();
auto *shm_pointer = reinterpret_cast<char *>(shmat(shmId, nullptr, 0));
semaphoreOperation(LOCK);
memcpy(shm_pointer + offset, data, size);
shmdt(shm_pointer); //close shm_pointer
semaphoreOperation(UNLOCK);
std::cout << "writing successed" << std::endl;
}
} }
char *getSharedMemory() { char *getSharedMemory() {

View File

@ -71,7 +71,7 @@ void logTime(){
} }
//log the message //log the message
void log(const std::string &msg, LogLevel level) { void log(LogLevel level, const std::string &msg) {
if(level >= logLevel) { if(level >= logLevel) {
std::string levelName = getLevelName(level); std::string levelName = getLevelName(level);
const int maxLevelNameLength = 8; const int maxLevelNameLength = 8;

View File

@ -2,6 +2,7 @@
#define LIBRARY_LOG_H #define LIBRARY_LOG_H
#include <string> #include <string>
#include <sstream>
enum LogLevel{ enum LogLevel{
DEBUG = 1, DEBUG = 1,
@ -17,7 +18,26 @@ enum LogLevel{
* @author Julian Hinxlage * @author Julian Hinxlage
* @since 0.1.0 * @since 0.1.0
*/ */
void log(const std::string &msg, LogLevel level = LogLevel::INFO); void log(LogLevel level, const std::string &msg);
template<typename T>
static void buildString(std::stringstream &stream, T t) {
stream << t;
}
template<typename T, typename... Ts>
static void buildString(std::stringstream &stream, T t, Ts... ts) {
stream << t;
buildString(stream, ts...);
}
template<typename... T>
static void log(LogLevel level, T... t){
std::stringstream stream;
buildString(stream, t...);
log(level, stream.str());
}
/** /**

View File

@ -7,6 +7,7 @@
#include "FontType.h" #include "FontType.h"
#include "KeyCode.h" #include "KeyCode.h"
#include "LayoutVersion.h" #include "LayoutVersion.h"
#include "log.h"
#include <functional> #include <functional>
#include <string> #include <string>