ublk-org / ublksrv

ublk: userspace block device driver
MIT License
147 stars 50 forks source link

An easier way to enable ublksrv log functions #41

Closed old-memories closed 1 year ago

old-memories commented 1 year ago

Hi Ming,

I find that ublksrv provides log functions but it is disabled by default. Is there any easier ways to enable them?

We could add "-DDEBUG" in CFLAGS while running ./configure but I think this is not handy for users. Or we could add these steps in README.

#ifdef DEBUG
static inline void ublksrv_log(int priority, const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    vsyslog(priority, fmt, ap);
}

static inline void ublksrv_printf(FILE *stream, const char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    vfprintf(stream, fmt, ap);
}
#else
static inline void ublksrv_log(int priority, const char *fmt, ...) { }
static inline void ublksrv_printf(FILE *stream, const char *fmt, ...) {}
#endif
ming1 commented 1 year ago

Hi Ziyang,

OK, we could add ./configure option for enabling debug switch, will do that and document in readme.

thanks,

ming1 commented 1 year ago

BTW, ublksrv log is improved now.

But, not support runtime logging, so for any logging still need to ./configure --enable-debug for passing -DDEBUG.

The improvement is adding debug masks for grouping logging info by passing --debug_mask to 'ublk add', see each kind of debug level: UBLKDBG* in include/ublksrv_utils.h