diff --git a/libmysyslog/Makefile b/libmysyslog/Makefile index c7a0433..6bafc98 100644 --- a/libmysyslog/Makefile +++ b/libmysyslog/Makefile @@ -1,23 +1,17 @@ CC = gcc -CFLAGS = -Wall -g -fPIC -LDFLAGS = +CFLAGS = -Wall -Wextra -fPIC +LDFLAGS = -shared +TARGET = libmysyslog.so -LIBRARY = libmysyslog.a -OBJ = src/mysyslog.o +all: $(TARGET) -all: $(LIBRARY) +$(TARGET): libmysyslog.o + $(CC) $(LDFLAGS) -o $@ $^ -$(LIBRARY): $(OBJ) - ar rcs $@ $^ +libmysyslog.o: libmysyslog.c libmysyslog.h + $(CC) $(CFLAGS) -c $< clean: - rm -f $(OBJ) $(LIBRARY) + rm -f *.o $(TARGET) -deb: - # Deb package building logic - -install: $(LIBRARY) - cp $(LIBRARY) /usr/local/lib - ldconfig - -.PHONY: all clean deb install +.PHONY: all clean \ No newline at end of file diff --git a/libmysyslog/debian/control b/libmysyslog/debian/control deleted file mode 100644 index a074a0c..0000000 --- a/libmysyslog/debian/control +++ /dev/null @@ -1,12 +0,0 @@ -Source: libmysyslog -Section: libs -Priority: optional -Maintainer: GandC Snow admin@gandc.ru -Build-Depends: debhelper (>= 9) -Standards-Version: 3.9.6 -Homepage: https://git.gandc.ru/mysyslog/libmysyslog - -Package: libmysyslog -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: Core library for the MySyslog logging system diff --git a/libmysyslog/debian/rules b/libmysyslog/debian/rules deleted file mode 100644 index 2d33f6a..0000000 --- a/libmysyslog/debian/rules +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/make -f - -%: - dh $@ diff --git a/libmysyslog/libmysyslog.c b/libmysyslog/libmysyslog.c new file mode 100644 index 0000000..95749a7 --- /dev/null +++ b/libmysyslog/libmysyslog.c @@ -0,0 +1,39 @@ +#include "libmysyslog.h" +#include +#include +#include + +static const char* log_levels[] = {"DEBUG", "INFO", "WARN", "ERROR", "CRITICAL"}; + +int log_to_text(const char* msg, int level, const char* path); +int log_to_json(const char* msg, int level, const char* path); + +int mysyslog(const char* msg, int level, int driver, int format, const char* path) { + if (driver == TEXT_DRIVER) { + return log_to_text(msg, level, path); + } else if (driver == JSON_DRIVER) { + return log_to_json(msg, level, path); + } else { + return -1; // Unsupported driver + } +} + +int log_to_text(const char* msg, int level, const char* path) { + FILE* file = fopen(path, "a"); + if (!file) return -1; + + time_t now = time(NULL); + fprintf(file, "%ld %s %s\n", now, log_levels[level], msg); + fclose(file); + return 0; +} + +int log_to_json(const char* msg, int level, const char* path) { + FILE* file = fopen(path, "a"); + if (!file) return -1; + + time_t now = time(NULL); + fprintf(file, "{\"timestamp\":%ld,\"log_level\":\"%s\",\"message\":\"%s\"}\n", now, log_levels[level], msg); + fclose(file); + return 0; +} \ No newline at end of file diff --git a/libmysyslog/libmysyslog.h b/libmysyslog/libmysyslog.h new file mode 100644 index 0000000..2748544 --- /dev/null +++ b/libmysyslog/libmysyslog.h @@ -0,0 +1,19 @@ +#ifndef LIBMYSYSLOG_H +#define LIBMYSYSLOG_H + +enum LogLevel { + DEBUG, + INFO, + WARN, + ERROR, + CRITICAL +}; + +enum LogDriver { + TEXT_DRIVER, + JSON_DRIVER +}; + +int mysyslog(const char* msg, int level, int driver, int format, const char* path); + +#endif // LIBMYSYSLOG_H \ No newline at end of file