summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/engine.c3
-rw-r--r--src/log.c3
-rw-r--r--src/logger/logger.h28
-rw-r--r--src/server.c7
4 files changed, 30 insertions, 11 deletions
diff --git a/src/engine.c b/src/engine.c
index c84e073..f34a83e 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -5,6 +5,7 @@
#include "fcntl.h"
#include "ipc.c"
+#define LOG_MODULE "engine"
#include "logger/logger.h"
struct sqrstr {
@@ -22,7 +23,7 @@ int main(void) {
while (1) {
char* x = read_queue(rx);
- log_infof("Engine received: %s", x);
+ log_infof("Received: %s", x);
free(x);
send_queue(tx, "Sending", 8);
diff --git a/src/log.c b/src/log.c
index 53198cd..64d738c 100644
--- a/src/log.c
+++ b/src/log.c
@@ -4,6 +4,8 @@
int main(int argc, char** argv) {
mqd_t rx = mq_open("/logs", O_CREAT | O_RDONLY, 0666, &attr);
+ mqd_t _ = mq_open("/server_to_engine", O_CREAT, 0666, &attr);
+ _ = mq_open("/engine_to_server", O_CREAT, 0666, &attr);
for (int i = 1; i < argc; i++) {
printf("Running: %s\n", argv[i]);
@@ -11,7 +13,6 @@ int main(int argc, char** argv) {
char* new_argv[] = {argv[i], NULL};
execvp(argv[i], new_argv);
}
- sleep(1);
}
while (1) {
diff --git a/src/logger/logger.h b/src/logger/logger.h
index dba4435..4a519aa 100644
--- a/src/logger/logger.h
+++ b/src/logger/logger.h
@@ -5,11 +5,21 @@
#define LOG_LEVEL 3
#endif
+#ifndef LOG_MODULE
+ #define HAS_LOG_MODULE 0
+ #define LOG_MODULE ""
+#else
+ #define HAS_LOG_MODULE 1
+#endif
+
#if LOG_LEVEL >= 3
#define log_infof(...) do { \
char log_buf[1024]; \
- log_buf[0] = 'i'; \
- snprintf(log_buf + 1, 1023, __VA_ARGS__); \
+ int n = 1; \
+ if (HAS_LOG_MODULE == 1) { \
+ n = snprintf(log_buf, 1024, "i(%s) ", LOG_MODULE); \
+ } \
+ snprintf(log_buf + n, 1024 - n, __VA_ARGS__); \
send_log(logging, log_buf, 1024); \
} while(0);
#endif // LOG_LEVEL >= 3
@@ -17,8 +27,11 @@
#if LOG_LEVEL >= 2
#define log_warnf(...) do { \
char log_buf[1024]; \
- log_buf[0] = 'w'; \
- snprintf(log_buf + 1, 1023, __VA_ARGS__); \
+ int n = 1; \
+ if (HAS_LOG_MODULE == 1) { \
+ n = snprintf(log_buf, 1024, "w(%s) ", LOG_MODULE); \
+ } \
+ snprintf(log_buf + n, 1024 - n, __VA_ARGS__); \
send_log(logging, log_buf, 1024) \
} while(0);
#endif // LOG_LEVEL >= 2
@@ -26,8 +39,11 @@
#if LOG_LEVEL >= 1
#define log_errof(...) do { \
char log_buf[1024]; \
- log_buf[0] = 'e'; \
- snprintf(log_buf + 1, 1023, __VA_ARGS__); \
+ int n = 1; \
+ if (HAS_LOG_MODULE == 1) { \
+ n = snprintf(log_buf, 1024, "e(%s) ", LOG_MODULE); \
+ } \
+ snprintf(log_buf + n, 1024 - n, __VA_ARGS__); \
send_log(logging, log_buf, 1024) \
} while(0);
#endif // LOG_LEVEL >= 1
diff --git a/src/server.c b/src/server.c
index 03b8433..ea18a68 100644
--- a/src/server.c
+++ b/src/server.c
@@ -8,6 +8,7 @@
#include <assert.h>
#include <unistd.h>
+#define LOG_MODULE "server"
#include "logger/logger.h"
#define PORT 3456
@@ -19,8 +20,8 @@
int main(void) {
mqd_t logging = mq_open("/logs", O_WRONLY);
- mqd_t tx = mq_open("/server_to_engine", O_CREAT | O_WRONLY, 0666, &attr);
- mqd_t rx = mq_open("/engine_to_server", O_CREAT | O_RDONLY, 0666, &attr);
+ mqd_t tx = mq_open("/server_to_engine", O_WRONLY);
+ mqd_t rx = mq_open("/engine_to_server", O_RDONLY);
int server_fd = socket(AF_INET, SOCK_STREAM, 0);
int opt = 1;
@@ -83,7 +84,7 @@ int main(void) {
);
send(client, response, strlen(response), 0);
- log_infof("WebSocket connected\n");
+ log_infof("WebSocket connected");
for (;;) {
unsigned char hdr[2];