Hi, On Wed, Dec 23, 2015 at 02:25:00PM +0000, Frediano Ziglio wrote: > Allow to log but no more than a fixed number of times. Can you give an example where this could be useful? My thinking about logging is that we should print info as much as necessary but we should be able to filter it in a smart way (without printing if we don't want to see it, or just the right levels...) So, I would like to understand where this function could be useful without loosing important warnings. > This to log for instance number of times client do something wrong > but without causing excessive log or DoS. > I didn't use atomic operation for decrementing the counter to reduce > possible contention on the system bus, this will just cause some > more messages to be printed. > The signed variable and the check assure that counter does not > underflow (unless machine has billions of processors and millions of > clients are connected). > > Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> > --- > common/log.h | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/common/log.h b/common/log.h > index d9e6023..bd5edc5 100644 > --- a/common/log.h > +++ b/common/log.h > @@ -103,6 +103,14 @@ void spice_log(const char *log_domain, > } SPICE_STMT_END > #endif > > +#define spice_warning_limit(n, format, ...) SPICE_STMT_START { \ > + static int warn_limit = (n); \ > + if (warn_limit > 0) { \ > + --warn_limit; \ > + spice_warning(format, ## __VA_ARGS__); \ > + } \ > +} SPICE_STMT_END The other defines align the ending '\' Reviewed-by: Victor Toso <victortoso@xxxxxxxxxx> cheers, toso > + > #ifndef spice_critical > #define spice_critical(format, ...) SPICE_STMT_START { \ > spice_log(SPICE_LOG_DOMAIN, SPICE_LOG_LEVEL_CRITICAL, SPICE_STRLOC, __FUNCTION__, format, ## __VA_ARGS__); \ > -- > 2.4.3 > > _______________________________________________ > Spice-devel mailing list > Spice-devel@xxxxxxxxxxxxxxxxxxxxx > http://lists.freedesktop.org/mailman/listinfo/spice-devel _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel