From: Martin Mares Date: Sat, 21 Feb 2009 19:31:30 +0000 (+0100) Subject: Logging: Write a note when some messages fall victim to limiting. X-Git-Tag: holmes-import~42 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=3d43028dc1bf91e8bd4e6546a59d68688595c2da;p=libucw.git Logging: Write a note when some messages fall victim to limiting. I was considering various shapes of this message. It is tempting to mention the number of dropped messages, but that has to be done at the time of an accepted message, which could be too late (the user might already have wondered about the fate of the missing messages). Second, I wanted to include a message type, but it would be misleading, since a single limiter can apply to more types at once with a common bucket. --- diff --git a/ucw/log-conf.c b/ucw/log-conf.c index 5d54d7f3..bda938fe 100644 --- a/ucw/log-conf.c +++ b/ucw/log-conf.c @@ -9,11 +9,13 @@ #include "ucw/lib.h" #include "ucw/log.h" +#include "ucw/log-internal.h" #include "ucw/conf.h" #include "ucw/simple-lists.h" #include "ucw/tbf.h" #include "ucw/threads.h" +#include #include #include #include @@ -216,12 +218,27 @@ log_limiter(struct log_stream *ls, struct log_msg *m) return 0; ASSERT(!(m->flags & L_SIGHANDLER)); - timestamp_t now = ((timestamp_t) m->tv->tv_sec * 1000) + (m->tv->tv_usec / 1000); + if (m->flags & L_LOGGER_ERR) + return 0; + timestamp_t now = ((timestamp_t) m->tv->tv_sec * 1000) + (m->tv->tv_usec / 1000); ucwlib_lock(); int res = tbf_limit(tbf, now); ucwlib_unlock(); - return !res; + + if (res < 0) + { + if (res == -1) + { + struct log_msg mm = *m; + mm.flags |= L_LOGGER_ERR; + mm.raw_msg = "(maximum logging rate exceeded, some messages will be suppressed)"; + log_pass_msg(0, ls, &mm); + } + return 1; + } + else + return 0; } static void @@ -313,6 +330,7 @@ log_configured(const char *name) #ifdef TEST +#include #include "ucw/getopt.h" int main(int argc, char **argv) @@ -324,7 +342,11 @@ int main(int argc, char **argv) int type = log_register_type("foo"); struct log_stream *ls = log_new_configured("combined"); - msg(L_INFO | ls->regnum | type, "Hello, universe!"); + for (uns i=0; i<10; i++) + { + msg(L_INFO | ls->regnum | type, "Hello, universe!"); + usleep(200000); + } log_close_all(); return 0;