On Wed, Jul 26, 2017 at 12:49:15PM +0100, Frediano Ziglio wrote: > VDLog::printf is called only using a VDLog pointer. > Since this class is a singleton, there can only be one instance of it, > so LOG() does not need really need to deal with it, VDLog::printf can > do that instead. "need really need" <- one extra "need" > This simplify LOG macros not having to choose between printf and simplifies.. by not having to choose.. > VDLog::printf. I'd insert a blank line at this point in the log Acked-by: Christophe Fergeau <cfergeau@xxxxxxxxxx> > The manual GNU __attribute__ is used as the format to use is > not the standard __printf__ format used in SPICE_GNUC_PRINTF > but you need to use the gnu_printf format. For instance the "%llu" > syntax is accepted by gnu_print format but not by __printf__ one. > MinGW C++ by default uses gnu_printf format for all formatting > functions. > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > --- > common/vdlog.cpp | 5 +++-- > common/vdlog.h | 12 +++++------- > 2 files changed, 8 insertions(+), 9 deletions(-) > > Changes since v1: > - improve comment > > diff --git a/common/vdlog.cpp b/common/vdlog.cpp > index b9ae93f..8af6dcc 100644 > --- a/common/vdlog.cpp > +++ b/common/vdlog.cpp > @@ -70,12 +70,13 @@ VDLog* VDLog::get(TCHAR* path) > > void VDLog::printf(const char* format, ...) > { > + FILE *fh = _log ? _log->_handle : stdout; > va_list args; > > va_start(args, format); > - vfprintf(_handle, format, args); > + vfprintf(fh, format, args); > va_end(args); > - fflush(_handle); > + fflush(fh); > } > > void log_version() > diff --git a/common/vdlog.h b/common/vdlog.h > index e645409..b1be391 100644 > --- a/common/vdlog.h > +++ b/common/vdlog.h > @@ -31,7 +31,10 @@ class VDLog { > public: > ~VDLog(); > static VDLog* get(TCHAR* path = NULL); > - void printf(const char* format, ...); > +#ifdef __GNUC__ > + __attribute__((__format__ (gnu_printf, 1, 2))) > +#endif > + static void printf(const char* format, ...); > > private: > VDLog(FILE* handle); > @@ -61,7 +64,6 @@ static const VDLogLevel log_level = LOG_INFO; > > #define LOG(type, format, ...) do { \ > if (type >= log_level && type <= LOG_FATAL) { \ > - VDLog* log = VDLog::get(); \ > const char *type_as_char[] = { "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }; \ > struct _timeb now; \ > struct tm today; \ > @@ -69,11 +71,7 @@ static const VDLogLevel log_level = LOG_INFO; > _ftime_s(&now); \ > localtime_s(&today, &now.time); \ > strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today); \ > - if (log) { \ > - log->PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \ > - } else { \ > - PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \ > - } \ > + VDLog::PRINT_LINE(type_as_char[type], format, datetime_str, now.millitm, ## __VA_ARGS__); \ > } \ > } while(0) > > -- > 2.13.3 > > _______________________________________________ > Spice-devel mailing list > Spice-devel@xxxxxxxxxxxxxxxxxxxxx > https://lists.freedesktop.org/mailman/listinfo/spice-devel
Attachment:
signature.asc
Description: PGP signature
_______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel