Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
mxq_log: Do not deduplicate messages
We intent to make loggin on info level less verbose so that we don'T
need the deduplication here.

At debug level we want to see all events as they happen.
  • Loading branch information
donald committed Jul 6, 2017
1 parent 3a7b5f6 commit 447cc7f
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions mxq_log.c
Expand Up @@ -46,45 +46,18 @@ int mx_log_print(char *msg, size_t len)
{
char timebuf[1024];

static char *lastmsg = NULL;
static size_t lastlen = 0;
static int cnt = 0;

if (!msg) {
mx_free_null(lastmsg);
return 0;
}

if (!len)
return 0;

if (!*msg)
return -(errno=EINVAL);

if (lastmsg && lastlen == len) {
if (mx_streq(msg, lastmsg)) {
cnt++;
mx_free_null(msg);
return 2;
}
}

timetag(timebuf, sizeof(timebuf));

if (cnt > 1)
fprintf(stderr, "%s %s[%d]: last message repeated %d times\n", timebuf, program_invocation_short_name, getpid(), cnt);
else if (cnt == 1)
fprintf(stderr, "%s %s[%d]: %s\n", timebuf, program_invocation_short_name, getpid(), lastmsg);

if (lastmsg)
mx_free_null(lastmsg);

lastmsg = msg;
lastlen = len;
cnt = 0;

fprintf(stderr, "%s %s[%d]: %s\n", timebuf, program_invocation_short_name, getpid(), msg);
fflush(stderr);
mx_free_null(msg);

return 1;
}

0 comments on commit 447cc7f

Please sign in to comment.