diff --git a/src/logging.c b/src/logging.c index c4ea46c..4e54a96 100644 --- a/src/logging.c +++ b/src/logging.c @@ -34,6 +34,7 @@ struct UCLogDestination { struct { FILE* file; char *file_name; //NULL for stderr destinaton + size_t size; //keeps track of no of bytes written } file; } type; }; @@ -161,6 +162,7 @@ struct UCLogDestination *uc_log_new_stderr(int log_level, int log_location) dest->dest_type = UC_LDEST_STDERR; dest->type.file.file = stderr; + dest->type.file.size = 0; dest->log_level = log_level;; dest->log_location = log_location; @@ -233,6 +235,7 @@ struct UCLogDestination *uc_log_new_file(const char *filename, int log_level, in dest->dest_type = UC_LDEST_FILE; dest->type.file.file = f; dest->type.file.file_name = name; + dest->type.file.size = 0; dest->log_level = log_level;; dest->log_location = log_location; @@ -387,6 +390,7 @@ int uc_log_reopen_files(void) if (dest->dest_type == UC_LDEST_FILE) { rc = uc_log_reopen_file(dest); + dest->type.file.size = 0; } } @@ -407,6 +411,7 @@ static inline void uc_vlog_file(const struct UCLogArgs *args, const char *fmt, v char time_buf[48]; time_t now; struct tm t; + int rc; if (dest->type.file.file == NULL) return; @@ -425,20 +430,25 @@ static inline void uc_vlog_file(const struct UCLogArgs *args, const char *fmt, v time_buf[sizeof time_buf -1] = 0; if (dest->log_location) { - fprintf(dest->type.file.file, "[%-7s] %s %s [%s] : ", + rc = fprintf(dest->type.file.file, "[%-7s] %s %s [%s] : ", uc_ll_2_str(args->log_level), time_buf, args->location, args->module->short_name); } else { - fprintf(dest->type.file.file, "[%-7s] %s [%s]: ", + rc = fprintf(dest->type.file.file, "[%-7s] %s [%s]: ", uc_ll_2_str(args->log_level), time_buf, args->module->short_name); } } + if (rc >= 0) { + dest->type.file.size += rc; + rc = vfprintf(dest->type.file.file, fmt, ap); + } - vfprintf(dest->type.file.file, fmt, ap); - - fflush(dest->type.file.file); //strictly not needed for stderr - // though stderr could be redirected to a file + if (rc >= 0) { + dest->type.file.size += rc; + rc = fflush(dest->type.file.file); //strictly not needed for stderr + // though stderr could be redirected to a file + } } static inline void uc_vlog_syslog(const struct UCLogArgs *args, const char *fmt, va_list ap)