Browse Source

Send all log messages to console while console logger hasn't been set up.

master
ckolivas 8 years ago committed by Con Kolivas
parent
commit
7d4c99b647
  1. 45
      src/ckpool.c

45
src/ckpool.c

@ -82,28 +82,19 @@ static void proclog(ckpool_t *ckp, char *msg)
}
/* Log everything to the logfile, but display warnings on the console as well */
void logmsg(int loglevel, const char *fmt, ...) {
if (global_ckp->loglevel >= loglevel && fmt) {
void logmsg(int loglevel, const char *fmt, ...)
{
int logfd = global_ckp->logfd;
char *buf = NULL, *log;
char *log, *buf = NULL;
char stamp[128];
struct tm tm;
tv_t now_tv;
int ms;
va_list ap;
char stamp[128];
va_start(ap, fmt);
VASPRINTF(&buf, fmt, ap);
va_end(ap);
int ms;
if (unlikely(!buf)) {
fprintf(stderr, "Null buffer sent to logmsg\n");
if (global_ckp->loglevel < loglevel || !fmt)
return;
}
if (unlikely(!strlen(buf))) {
fprintf(stderr, "Zero length string sent to logmsg\n");
return;
}
tv_time(&now_tv);
ms = (int)(now_tv.tv_usec / 1000);
localtime_r(&(now_tv.tv_sec), &tm);
@ -114,18 +105,36 @@ void logmsg(int loglevel, const char *fmt, ...) {
tm.tm_hour,
tm.tm_min,
tm.tm_sec, ms);
va_start(ap, fmt);
VASPRINTF(&buf, fmt, ap);
va_end(ap);
if (unlikely(!buf)) {
fprintf(stderr, "Null buffer sent to logmsg\n");
return;
}
if (unlikely(!strlen(buf))) {
fprintf(stderr, "Zero length string sent to logmsg\n");
goto out;
}
if (loglevel <= LOG_ERR && errno != 0)
ASPRINTF(&log, "%s %s with errno %d: %s\n", stamp, buf, errno, strerror(errno));
else
ASPRINTF(&log, "%s %s\n", stamp, buf);
if (unlikely(!global_ckp->console_logger)) {
fprintf(stderr, "%s", log);
goto out_free;
}
if (loglevel <= LOG_WARNING)
ckmsgq_add(global_ckp->console_logger, strdup(log));
if (logfd > 0)
ckmsgq_add(global_ckp->logger, strdup(log));
free(buf);
out_free:
free(log);
}
out:
free(buf);
}
/* Generic function for creating a message queue receiving and parsing thread */

Loading…
Cancel
Save