add new content
This commit is contained in:
parent
7fc9618d17
commit
5a7a9ad8bb
@ -1,18 +1,17 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -g
|
||||
LDFLAGS = -lm
|
||||
CFLAGS = -Wall -Wextra -I../libmysyslog
|
||||
LDFLAGS = -L../libmysyslog -lmysyslog
|
||||
TARGET = libmysyslog-client
|
||||
|
||||
LIBS = -lmysyslog -lmysyslog-text -lmysyslog-json
|
||||
all: $(TARGET)
|
||||
|
||||
all: mysyslog-client
|
||||
$(TARGET): libmysyslog-client.o
|
||||
$(CC) -o $(TARGET) libmysyslog-client.o $(LDFLAGS)
|
||||
|
||||
mysyslog-client: src/mysyslog-client.o
|
||||
$(CC) -o $@ $^ $(LIBS)
|
||||
libmysyslog.o: libmysyslog-client.c
|
||||
$(cc) $(CFLAGS) -c libmysyslog-client.c
|
||||
|
||||
clean:
|
||||
rm -f src/*.o mysyslog-client
|
||||
rm -f $(TARGET) *.o
|
||||
|
||||
deb:
|
||||
# Deb package building logic
|
||||
|
||||
.PHONY: all clean deb
|
||||
.PHONY: all clean
|
||||
|
||||
52
mysyslog-client/libmysyslog-client.c
Normal file
52
mysyslog-client/libmysyslog-client.c
Normal file
@ -0,0 +1,52 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include "libmysyslog.h"
|
||||
|
||||
void print_usage(const char* prog_name) {
|
||||
printf("Usage: %s -m <message> -l <log_level> -d <driver> -f <format> -p <path>\n", prog_name);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int opt;
|
||||
char* message = NULL;
|
||||
int level = INFO;
|
||||
int driver = TEXT_DRIVER;
|
||||
int format = 0;
|
||||
char* path = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "m:l:d:f:p:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'm':
|
||||
message = 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;
|
||||
default:
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if (!message || !path) {
|
||||
print_usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (mysyslog(message, level, driver, format, path) != 0) {
|
||||
fprintf(stderr, "Failed to log message\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
#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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user