|
|
@ -82,50 +82,59 @@ static void proclog(ckpool_t *ckp, char *msg) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Log everything to the logfile, but display warnings on the console as well */ |
|
|
|
/* Log everything to the logfile, but display warnings on the console as well */ |
|
|
|
void logmsg(int loglevel, const char *fmt, ...) { |
|
|
|
void logmsg(int loglevel, const char *fmt, ...) |
|
|
|
if (global_ckp->loglevel >= loglevel && fmt) { |
|
|
|
{ |
|
|
|
int logfd = global_ckp->logfd; |
|
|
|
int logfd = global_ckp->logfd; |
|
|
|
char *buf = NULL, *log; |
|
|
|
char *log, *buf = NULL; |
|
|
|
struct tm tm; |
|
|
|
char stamp[128]; |
|
|
|
tv_t now_tv; |
|
|
|
struct tm tm; |
|
|
|
int ms; |
|
|
|
tv_t now_tv; |
|
|
|
va_list ap; |
|
|
|
va_list ap; |
|
|
|
char stamp[128]; |
|
|
|
int ms; |
|
|
|
|
|
|
|
|
|
|
|
va_start(ap, fmt); |
|
|
|
|
|
|
|
VASPRINTF(&buf, fmt, ap); |
|
|
|
|
|
|
|
va_end(ap); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (unlikely(!buf)) { |
|
|
|
if (global_ckp->loglevel < loglevel || !fmt) |
|
|
|
fprintf(stderr, "Null buffer sent to logmsg\n"); |
|
|
|
return; |
|
|
|
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); |
|
|
|
|
|
|
|
sprintf(stamp, "[%d-%02d-%02d %02d:%02d:%02d.%03d]", |
|
|
|
|
|
|
|
tm.tm_year + 1900, |
|
|
|
|
|
|
|
tm.tm_mon + 1, |
|
|
|
|
|
|
|
tm.tm_mday, |
|
|
|
|
|
|
|
tm.tm_hour, |
|
|
|
|
|
|
|
tm.tm_min, |
|
|
|
|
|
|
|
tm.tm_sec, ms); |
|
|
|
|
|
|
|
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 (loglevel <= LOG_WARNING) |
|
|
|
tv_time(&now_tv); |
|
|
|
ckmsgq_add(global_ckp->console_logger, strdup(log)); |
|
|
|
ms = (int)(now_tv.tv_usec / 1000); |
|
|
|
if (logfd > 0) |
|
|
|
localtime_r(&(now_tv.tv_sec), &tm); |
|
|
|
ckmsgq_add(global_ckp->logger, strdup(log)); |
|
|
|
sprintf(stamp, "[%d-%02d-%02d %02d:%02d:%02d.%03d]", |
|
|
|
free(buf); |
|
|
|
tm.tm_year + 1900, |
|
|
|
free(log); |
|
|
|
tm.tm_mon + 1, |
|
|
|
|
|
|
|
tm.tm_mday, |
|
|
|
|
|
|
|
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)); |
|
|
|
|
|
|
|
out_free: |
|
|
|
|
|
|
|
free(log); |
|
|
|
|
|
|
|
out: |
|
|
|
|
|
|
|
free(buf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Generic function for creating a message queue receiving and parsing thread */ |
|
|
|
/* Generic function for creating a message queue receiving and parsing thread */ |
|
|
|