diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-05-30 21:23:44 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-05-30 21:23:44 +0100 |
commit | 6d183c02a50a42743c3031532f458ab5cea0685d (patch) | |
tree | d1463e8f53df26ec5f8c3c13a77880d11d3bc57f /logging.c | |
parent | ef93f4d61f03faa0edd60f11c7790ad3b67b44d4 (diff) |
Convert debugprint() from being to file/screen/disabled to always being to file with configurable verbosity.
Diffstat (limited to 'logging.c')
-rw-r--r-- | logging.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -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); } |