aboutsummaryrefslogtreecommitdiffstats
path: root/src/ckerrlog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ckerrlog.c')
-rw-r--r--src/ckerrlog.c116
1 files changed, 57 insertions, 59 deletions
diff --git a/src/ckerrlog.c b/src/ckerrlog.c
index 9e1fc51..9a63ffd 100644
--- a/src/ckerrlog.c
+++ b/src/ckerrlog.c
@@ -12,13 +12,14 @@
#include "ckerrlog.h"
#include "ckutil.h"
+#include "cklist.h"
-#define COMPONENT "ckerrlog"
+ERRLOG(ckerrlog);
static int loglvl;
static char buf[STR_M];
-#define X(stream) static char *stream;
+#define X(stream) static cklist *stream;
CK_STREAMS
#undef X
@@ -39,53 +40,65 @@ void initialize_errlog() {
cklog("%s Log session started", get_time());
}
-void report_errlog() {
- if (err)
- printf("Errors:\n%s", err);
- free(err);
- if (log)
- printf("Logs:\n%s", log);
- free(log);
-}
+#define X(stream) \
+ void add_ ## stream ## _with_delim(char *delim, char *txt, \
+ va_list args) { \
+ char tmp[STR_L]; \
+ vsprintf(tmp, txt, args); \
+ if (stream) { \
+ list_add(stream, tmp); \
+ list_add(stream, delim); \
+ return; \
+ } \
+ stream = list_make_and_add(tmp); \
+ list_add(stream, delim); \
+ }
+CK_STREAMS
+#undef X
-#define X(stream) \
- void add_ ## stream ## _with_delim(char *delim, char *txt, \
- va_list args) { \
- char tmp[STR_L]; \
- vsprintf(tmp, txt, args); \
- if (stream) { \
- stream = (char *)realloc(stream, strlen(stream) + \
- strlen(tmp) + strlen(delim) + 1); \
- strcat(stream, tmp); \
- strcat(stream, delim); \
- return; \
- } \
- stream = (char *)malloc(strlen(tmp) + strlen(delim) + 1); \
- strcpy(stream, tmp); \
- strcat(stream, delim); \
+#define X(stream) \
+ void ck## stream(char *txt, ...) { \
+ va_list args; \
+ va_start(args, txt); \
+ add_## stream ##_with_delim("\n", txt, args); \
+ va_end(args); \
}
CK_STREAMS
#undef X
-void ckerr(char *txt, ...) {
- va_list args;
- va_start(args, txt);
- add_err_with_delim("\n", txt, args);
- va_end(args);
-}
+#define X(stream) \
+ void reset_## stream() { \
+ list_free(stream); \
+ stream = NULL; \
+ }
+CK_STREAMS
+#undef X
-void cklog(char *txt, ...) {
- va_list args;
- va_start(args, txt);
- add_log_with_delim("\n", txt, args);
- va_end(args);
-}
+#define X(stream) \
+ void report_## stream() { \
+ list_print_concat(stream); \
+ reset_## stream(); \
+ }
+CK_STREAMS
+#undef X
-void ckhelp(char *txt, ...) {
- va_list args;
- va_start(args, txt);
- add_help_with_delim("\n", txt, args);
- va_end(args);
+void report_errlog() {
+ if (!loglvl) {
+#define X(stream) \
+ if (stream) { \
+ reset_##stream(); \
+ }
+ CK_STREAMS
+#undef X
+ return;
+ }
+#define X(stream) \
+ if (stream) { \
+ printf("%s:\n", #stream); \
+ report_##stream(); \
+ }
+ CK_STREAMS
+#undef X
}
void ckerr_add_component(char *txt, ...) {
@@ -95,21 +108,6 @@ void ckerr_add_component(char *txt, ...) {
va_end(args);
}
-void ckhelp_add_component(char *txt, ...) {
- va_list args;
- va_start(args, txt);
- add_help_with_delim(" ", txt, args);
- va_end(args);
-}
-
-void report_err() {
- printf("%s", err);
- free(err);
- err = NULL;
-}
-
-void report_help() {
- printf("%s", help);
- free(help);
- help = NULL;
+extern void errlog_set_verbose(int level) {
+ loglvl = level;
}