summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-10-29 13:37:41 -0400
committerCara Salter <cara@devcara.com>2022-10-29 13:37:41 -0400
commit9f6108784ceb997ce388e5212d36ed86ad3934df (patch)
treed0a38b3a8935333ee12cd4b893a64806412b084b
downloadclog-9f6108784ceb997ce388e5212d36ed86ad3934df.tar.gz
clog-9f6108784ceb997ce388e5212d36ed86ad3934df.zip
Initial commit
-rw-r--r--Makefile30
-rw-r--r--clog.c121
-rw-r--r--clog.h25
3 files changed, 176 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..44dd1d4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,30 @@
+CC=gcc
+CFLAGS=-I. -Wall -fPIC
+MAJOR=0
+MINOR=1
+VERSION=$(MAJOR).$(MINOR)
+NAME=clog
+DESTDIR?=/usr/local/lib
+
+LFLAGS=
+
+%.o: %.c
+ $(CC) -c -o $@ $< $(CFLAGS)
+
+lib: lib$(NAME).so.$(VERSION)
+
+lib$(NAME).so:
+ ldconfig -v -n
+ ln -s lib$(NAME).so.$(MAJOR) lib$(NAME).so
+
+lib$(NAME).so.$(VERSION): $(NAME).o
+ $(CC) -shared $^ -o $@
+
+install: lib
+ install -Dm644 lib$(NAME).so.$(VERSION) $(DESTDIR)
+ install -Dm644 $(NAME).h /usr/include/
+
+clean:
+ rm -f lib$(NAME)*
+ rm -f src/*.o
+
diff --git a/clog.c b/clog.c
new file mode 100644
index 0000000..409ba21
--- /dev/null
+++ b/clog.c
@@ -0,0 +1,121 @@
+/*
+ * =====================================================================================
+ *
+ * Filename: log.c
+ *
+ * Description: Implementations for logging framework
+ *
+ * Version: 1.0
+ * Created: 10/27/2022 10:02:48 AM
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: Cara Salter (cara@devcara.com)
+ * Organization:
+ *
+ * =====================================================================================
+ */
+
+#define _GNU_SOURCE
+/* ##### HEADER FILE INCLUDES ################################################### */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+
+
+/* ##### PROTOTYPES - LOCAL TO THIS SOURCE FILE ############################### */
+void process_fmt(char* msg, va_list args);
+
+/* ##### FUNCTION DEFINITIONS - LOCAL TO THIS SOURCE FILE ##################### */
+
+
+/*
+ * === FUNCTION ======================================================================
+ * Name: print_date
+ * Description: Prints the current date/time to stdout without a newline =====================================================================================
+ */
+void print_date() {
+ time_t cur_time = time(NULL);
+ struct tm t = *localtime(&cur_time);
+
+ printf("%d-%02d-%02d %02d:%02d:%02d", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
+} /* ----- end of function print_date ----- */
+/*
+ * === FUNCTION ======================================================================
+ * Name: debug
+ * Description: Outputs debugging information to stdout
+ * =====================================================================================
+ */
+int debug(char* msg, ...) {
+ va_list args;
+ print_date();
+ va_start(args, msg);
+ char *fmt_string;
+ vasprintf(&fmt_string, msg, args);
+ printf(" \033[34mDEBUG\033[0m %s\n", fmt_string);
+ free(fmt_string);
+ va_end(args);
+ return 0;
+}
+
+
+/*
+ * === FUNCTION ======================================================================
+ * Name: info
+ * Description: Outputs informational messages to stdout
+ * =====================================================================================
+ */
+int info(char* msg, ...) {
+ va_list args;
+ print_date();
+ va_start(args, msg);
+ char *fmt_string;
+ vasprintf(&fmt_string, msg, args);
+ printf(" \033[32mINFO\033[0m %s\n", fmt_string);
+ free(fmt_string);
+ va_end(args);
+ return 0;
+} /* ----- end of function info ----- */
+
+
+/*
+ * === FUNCTION ======================================================================
+ * Name: warning
+ * Description: Outputs a warning message to stdout
+ * =====================================================================================
+ */
+int warning(char* msg, ...) {
+ va_list args;
+
+ print_date();
+ va_start(args, msg);
+ char *fmt_string;
+ vasprintf(&fmt_string, msg, args);
+ printf(" \033[33mWARNING\033[0m %s\n", fmt_string);
+ free(fmt_string);
+ va_end(args);
+ return 0;
+} /* ----- end of function warning ----- */
+
+
+/*
+ * === FUNCTION ======================================================================
+ * Name: error
+ * Description: Outputs an error to stdout and stderr
+ * =====================================================================================
+ */
+int error(char* msg, ...) {
+ va_list args;
+ print_date();
+ va_start(args, msg);
+ char *fmt_string;
+ vasprintf(&fmt_string, msg, args);
+ printf(" \033[31mERROR\033[0m %s\n", fmt_string);
+ fprintf(stderr, " \033[31mERROR\033[0m %s\n", fmt_string);
+ free(fmt_string);
+ va_end(args);
+ return 0;
+} /* ----- end of function error ----- */
+
diff --git a/clog.h b/clog.h
new file mode 100644
index 0000000..67c11f4
--- /dev/null
+++ b/clog.h
@@ -0,0 +1,25 @@
+/*
+ * =====================================================================================
+ *
+ * Filename: log.h
+ *
+ * Description: Header file for logging framework
+ *
+ * Version: 1.0
+ * Created: 10/27/2022 09:56:57 AM
+ * Revision: none
+ * Compiler: gcc
+ *
+ * Author: Cara Salter (cara@devcara.com)
+ * Organization:
+ *
+ * =====================================================================================
+ */
+
+
+/* ##### EXPORTED FUNCTION DECLARATIONS ######################################### */
+
+int debug(char* msg, ...);
+int info(char* msg, ...);
+int warning(char* msg, ...);
+int error(char* msg, ...);