diff options
author | Keuin <[email protected]> | 2021-12-28 05:37:54 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2021-12-28 05:37:54 +0800 |
commit | 94d7588c2045cbe76ec0287a5e92f1b4123d996f (patch) | |
tree | 651b547091858b1fbf536bf7b5209a90c32b1281 /logging.c |
Initial version.
Diffstat (limited to 'logging.c')
-rw-r--r-- | logging.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/logging.c b/logging.c new file mode 100644 index 0000000..2ad1704 --- /dev/null +++ b/logging.c @@ -0,0 +1,26 @@ +// +// Created by Keuin on 2021/12/28. +// + +#include "logging.h" +#include <stdio.h> + + +void *log_init(const char *filename) { + FILE *fp = fopen(filename, "a"); + return fp; +} + +void log_free(void *logger) { + fflush(logger); + fclose(logger); +} + +void log_print(void *logger, const char *level, time_t ts, const char *filename, int lineno, const char *msg) { + char timestr[32]; + strftime(timestr, 31, "%Y-%m-%d %H:%M:%S", localtime(&ts)); + if (fprintf(logger, "[%s][%s][%s][%d] %s\n", timestr, level, filename, lineno, msg)) + fflush(logger); + if (fprintf(stderr, "[%s][%s][%s][%d] %s\n", timestr, level, filename, lineno, msg)) + fflush(stderr); +} |