create project structure

This commit is contained in:
2024-11-23 18:47:32 +03:00
parent 75f3e942e6
commit 15c07a898b
13 changed files with 221 additions and 0 deletions

23
libmysyslog-json/Makefile Normal file
View File

@@ -0,0 +1,23 @@
CC = gcc
CFLAGS = -Wall -g -fPIC
LDFLAGS =
LIBRARY = libmysyslog-json.a
OBJ = src/log_json.o
all: $(LIBRARY)
$(LIBRARY): $(OBJ)
ar rcs $@ $^
clean:
rm -f $(OBJ) $(LIBRARY)
deb:
# Deb package building logic
install: $(LIBRARY)
cp $(LIBRARY) /usr/local/lib
ldconfig
.PHONY: all clean deb install

View File

@@ -0,0 +1,8 @@
#ifndef LOG_JSON_H
#define LOG_JSON_H
#include "mysyslog.h"
void log_json(const char* msg, LogLevel level, const char* path);
#endif // LOG_JSON_H

View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include <time.h>
#include "log_json.h"
void log_json(const char* msg, LogLevel level, const char* path) {
FILE* f = fopen(path, "a");
if (!f) return;
time_t t = time(NULL);
struct tm* tm_info = localtime(&t);
// Format log entry in JSON
fprintf(f, "{\"timestamp\": %ld, \"log_level\": \"%d\", \"process\": \"example-app\", \"message\": \"%s\"}\n", t, level, msg);
fclose(f);
}