+ logging with multiple arguments
This commit is contained in:
parent
051f366411
commit
0ae6f39f86
@ -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() {
|
||||||
|
@ -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;
|
||||||
|
22
src/log.h
22
src/log.h
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user