create project structure
This commit is contained in:
parent
75f3e942e6
commit
15c07a898b
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);
|
||||
}
|
||||
23
libmysyslog-text/Makefile
Normal file
23
libmysyslog-text/Makefile
Normal file
@ -0,0 +1,23 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -g -fPIC
|
||||
LDFLAGS =
|
||||
|
||||
LIBRARY = libmysyslog-text.a
|
||||
OBJ = src/log_text.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-text/include/log_text.h
Normal file
8
libmysyslog-text/include/log_text.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef LOG_TEXT_H
|
||||
#define LOG_TEXT_H
|
||||
|
||||
#include "mysyslog.h"
|
||||
|
||||
void log_text(const char* msg, LogLevel level, const char* path);
|
||||
|
||||
#endif // LOG_TEXT_H
|
||||
15
libmysyslog-text/src/log_text.c
Normal file
15
libmysyslog-text/src/log_text.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include "log_text.h"
|
||||
|
||||
void log_text(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
|
||||
fprintf(f, "%ld %d example-app %s\n", t, level, msg);
|
||||
fclose(f);
|
||||
}
|
||||
23
libmysyslog/Makefile
Normal file
23
libmysyslog/Makefile
Normal file
@ -0,0 +1,23 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -g -fPIC
|
||||
LDFLAGS =
|
||||
|
||||
LIBRARY = libmysyslog.a
|
||||
OBJ = src/mysyslog.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
|
||||
12
libmysyslog/debian/control
Normal file
12
libmysyslog/debian/control
Normal file
@ -0,0 +1,12 @@
|
||||
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
|
||||
4
libmysyslog/debian/rules
Normal file
4
libmysyslog/debian/rules
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
%:
|
||||
dh $@
|
||||
18
mysyslog-client/Makefile
Normal file
18
mysyslog-client/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -g
|
||||
LDFLAGS = -lm
|
||||
|
||||
LIBS = -lmysyslog -lmysyslog-text -lmysyslog-json
|
||||
|
||||
all: mysyslog-client
|
||||
|
||||
mysyslog-client: src/mysyslog-client.o
|
||||
$(CC) -o $@ $^ $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f src/*.o mysyslog-client
|
||||
|
||||
deb:
|
||||
# Deb package building logic
|
||||
|
||||
.PHONY: all clean deb
|
||||
29
mysyslog-client/src/mysyslog-client.c
Normal file
29
mysyslog-client/src/mysyslog-client.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include "mysyslog.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int level = INFO;
|
||||
int driver = 1; // Default to text driver
|
||||
int format = 1; // Default to text format
|
||||
const char* msg = NULL;
|
||||
const char* path = "/var/log/mysyslog.log";
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "m:l:d:f:p:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'm': msg = optarg; break;
|
||||
case 'l': level = atoi(optarg); break;
|
||||
case 'd': driver = atoi(optarg); break;
|
||||
case 'f': format = atoi(optarg); break;
|
||||
case 'p': path = optarg; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (msg != NULL) {
|
||||
mysyslog(msg, level, driver, format, path);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
mysyslog-daemon/Makefile
Normal file
16
mysyslog-daemon/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -g
|
||||
LDFLAGS = -lm
|
||||
|
||||
LIBS = -lmysyslog -lmysyslog-text -lmysyslog-json
|
||||
|
||||
all: mysyslog-daemon
|
||||
|
||||
mysyslog-daemon: src/mysyslog-daemon.o
|
||||
$(CC) -o $@ $^ $(LIBS)
|
||||
|
||||
clean: rm -f src/*.o mysyslog-daemon
|
||||
|
||||
deb: # Deb package building logic
|
||||
|
||||
.PHONY: all clean deb
|
||||
27
mysyslog-daemon/src/mysyslog-daemon.c
Normal file
27
mysyslog-daemon/src/mysyslog-daemon.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include "mysyslog.h"
|
||||
|
||||
static volatile int keep_running = 1;
|
||||
|
||||
void int_handler(int dummy) {
|
||||
keep_running = 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
signal(SIGINT, int_handler);
|
||||
signal(SIGTERM, int_handler);
|
||||
|
||||
const char* path = "/var/log/mysyslog.log";
|
||||
int driver = 1; // Default to text driver
|
||||
int format = 1; // Default to text format
|
||||
|
||||
while (keep_running) {
|
||||
mysyslog("Daemon log message", INFO, driver, format, path);
|
||||
sleep(60); // Log every minute
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user