/*---------- facilities for consuming log messages ----------*/
-#define XTL_STDIOSTREAM_SHOW_PID 01u
-#define XTL_STDIOSTREAM_SHOW_DATE 02u
-#define XTL_STDIOSTREAM_HIDE_PROGRESS 04u
+#define XTL_STDIOSTREAM_SHOW_PID 001u
+#define XTL_STDIOSTREAM_SHOW_DATE 002u
+#define XTL_STDIOSTREAM_HIDE_PROGRESS 004u
+#define XTL_STDIOSTREAM_PROGRESS_USE_CR 010u /* default is to */
+#define XTL_STDIOSTREAM_PROGRESS_NO_CR 020u /* use \r to ttys */
typedef struct xentoollog_logger_stdiostream xentoollog_logger_stdiostream;
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <stdbool.h>
struct xentoollog_logger_stdiostream {
xentoollog_logger vtable;
xentoollog_level min_level;
unsigned flags;
int progress_erase_len, progress_last_percent;
- int tty;
+ bool progress_use_cr;
};
static void progress_erase(xentoollog_logger_stdiostream *lg) {
lg->progress_last_percent = percent;
- if (!lg->tty) {
+ if (!lg->progress_use_cr) {
stdiostream_message(logger_in, this_level, context,
"%s: %lu/%lu %3d%%",
doing_what, done, total, percent);
newlogger.f = f;
newlogger.min_level = min_level;
newlogger.flags = flags;
- newlogger.tty = isatty(fileno(newlogger.f)) > 0;
+
+ switch (flags & (XTL_STDIOSTREAM_PROGRESS_USE_CR |
+ XTL_STDIOSTREAM_PROGRESS_NO_CR)) {
+ case XTL_STDIOSTREAM_PROGRESS_USE_CR: newlogger.progress_use_cr = 1; break;
+ case XTL_STDIOSTREAM_PROGRESS_NO_CR: newlogger.progress_use_cr = 0; break;
+ case 0:
+ newlogger.progress_use_cr = isatty(fileno(newlogger.f)) > 0;
+ break;
+ default:
+ errno = EINVAL;
+ return 0;
+ }
if (newlogger.flags & XTL_STDIOSTREAM_SHOW_DATE) tzset();