From 6d183c02a50a42743c3031532f458ab5cea0685d Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Thu, 30 May 2019 21:23:44 +0100 Subject: Convert debugprint() from being to file/screen/disabled to always being to file with configurable verbosity. --- logging.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'logging.c') diff --git a/logging.c b/logging.c index 23e2170..973d03c 100644 --- a/logging.c +++ b/logging.c @@ -57,7 +57,7 @@ int logline(char *str, char *ournick, char *basedir, int type) { } // Copy into the token array (strlen + 1 to get the NULL terminator) strncpy(tokens[i], token, strlen(token) + 1); - debugprint("logline(): extracted '%s'.\n", tokens[i]); + debugprint(DEBUG_FULL, "logline(): extracted '%s'.\n", tokens[i]); } switch(type) { @@ -77,7 +77,7 @@ int logline(char *str, char *ournick, char *basedir, int type) { snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, tokens[2]); } - debugprint("logline(): Logging PRIVMSG from '%s' to '%s' message '%s' in filename '%s'.\n", tokens[0], tokens[2], str, filename); + debugprint(DEBUG_FULL, "logline(): Logging PRIVMSG from '%s' to '%s' message '%s' in filename '%s'.\n", tokens[0], tokens[2], str, filename); break; @@ -97,7 +97,7 @@ int logline(char *str, char *ournick, char *basedir, int type) { snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, tokens[2] + pos); - debugprint("logline(): Logging JOIN/PART to/from '%s' in filename '%s'.\n", tokens[2] + pos, filename); + debugprint(DEBUG_FULL, "logline(): Logging JOIN/PART to/from '%s' in filename '%s'.\n", tokens[2] + pos, filename); // Build a friendly message (e.g. ":nick!user@host JOIN #channel" -> "nick (user@host) has joined #channel") @@ -136,7 +136,7 @@ int logline(char *str, char *ournick, char *basedir, int type) { snprintf(filename, MAXCHAR, "%s/logs/%s.log", basedir, tokens[2]); - debugprint("logline(): Logging TOPIC for '%s' in filename '%s'.\n", tokens[2], filename); + debugprint(DEBUG_FULL, "logline(): Logging TOPIC for '%s' in filename '%s'.\n", tokens[2], filename); // Build a friendly message (e.g. ":nick!user@host TOPIC #channel :blah blah" -> "nick has changed the topic to: blah blah") snprintf(line, MAXCHAR, "%s has changed the topic to: %s", tokens[0], str); @@ -154,10 +154,11 @@ int logline(char *str, char *ournick, char *basedir, int type) { struct stat st = {0}; if (stat(logdir, &st) == -1) { if (mkdir(logdir, 0700)) { + debugprint(DEBUG_CRIT, "Error creating log directory '%s.\n", logdir); printf("Error creating log directory '%s'.\n", logdir); exit(1); } else { - debugprint("logline(): log directory '%s'.\n", logdir); + debugprint(DEBUG_FULL, "logline(): log directory '%s'.\n", logdir); } } @@ -168,6 +169,7 @@ int logline(char *str, char *ournick, char *basedir, int type) { fp = fopen(filename, "a"); if (fp == NULL) { + debugprint(DEBUG_CRIT, "error: could not open log file '%s' for writing.\n", filename); printf("error: could not open log file '%s' for writing.\n", filename); exit(1); } @@ -202,10 +204,11 @@ int logline(char *str, char *ournick, char *basedir, int type) { // Ensure the line finishes with CRLF appendcrlf(line); - debugprint("logline(): Complete log string to write: '%s', length '%ld'.\n", line, strlen(line)); + debugprint(DEBUG_FULL, "logline(): Complete log string to write: '%s', length '%ld'.\n", line, strlen(line)); // Write complete line to file if ((bytes = fprintf(fp, "%s", line)) < 0) { + debugprint(DEBUG_CRIT, "error: could not write to log file.\n"); printf("error: could not write to log file.\n"); exit(1); } -- cgit v1.2.3