print: print warnings and errors to stderr

cute-signatures
Shiz 2017-04-10 08:47:22 +02:00 committed by William Pitcock
parent 515f31eb52
commit 5ba27c9000
2 changed files with 23 additions and 11 deletions

View File

@ -14,13 +14,14 @@
#include "apk_blob.h" #include "apk_blob.h"
#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0) #define apk_error(args...) do { apk_log_err("ERROR: ", args); } while (0)
#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0) #define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log_err("WARNING: ", args); } } while (0)
#define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0) #define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0)
extern int apk_progress_fd; extern int apk_progress_fd;
void apk_log(const char *prefix, const char *format, ...); void apk_log(const char *prefix, const char *format, ...);
void apk_log_err(const char *prefix, const char *format, ...);
const char *apk_error_str(int error); const char *apk_error_str(int error);
void apk_reset_screen_width(void); void apk_reset_screen_width(void);

View File

@ -157,17 +157,28 @@ const char *apk_error_str(int error)
} }
} }
void apk_log(const char *prefix, const char *format, ...) static void log(FILE *dest, const char *prefix, const char *format, va_list va)
{ {
va_list va;
if (prefix != NULL) if (prefix != NULL)
fprintf(stdout, "%s", prefix); fprintf(dest, "%s", prefix);
va_start(va, format); vfprintf(dest, format, va);
vfprintf(stdout, format, va); fprintf(dest, "\n");
va_end(va); fflush(dest);
fprintf(stdout, "\n");
fflush(stdout);
apk_progress_force = 1; apk_progress_force = 1;
} }
void apk_log(const char *prefix, const char *format, ...)
{
va_list va;
va_start(va, format);
log(stdout, prefix, format, va);
va_end(va);
}
void apk_log_err(const char *prefix, const char *format, ...)
{
va_list va;
va_start(va, format);
log(stderr, prefix, format, va);
va_end(va);
}