create project structure
This commit is contained in:
23
libmysyslog-json/Makefile
Normal file
23
libmysyslog-json/Makefile
Normal 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
|
||||
8
libmysyslog-json/include/log_json.h
Normal file
8
libmysyslog-json/include/log_json.h
Normal 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
|
||||
15
libmysyslog-json/src/log_json.c
Normal file
15
libmysyslog-json/src/log_json.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user