Rework syslogging

This commit is contained in:
Nils O. Selåsdal
2012-11-08 23:44:35 +01:00
parent c582a33365
commit 59e31761c3
+10 -5
View File
@@ -347,19 +347,19 @@ static inline void uc_vlog_syslog(const struct uc_log_args *args, const char *fm
int pri = uc_ll_2_syslog(args->log_level); int pri = uc_ll_2_syslog(args->log_level);
if(!args->raw) {
//go via a buffer as we must do just 1 syslog call //go via a buffer as we must do just 1 syslog call
char buf[4096]; char buf[4096];
int offset = 0; int offset = 0;
int rc;
buf[0] = 0; buf[0] = 0;
if(!args->raw) {
int rc;
if(dest->log_location) { if(dest->log_location) {
rc = snprintf(buf, sizeof buf, "%s:%d ", args->file, args->line); rc = snprintf(buf, sizeof buf, "%s:%d ", args->file, args->line);
if(rc < 0) if(rc < 0)
goto log; goto log;
offset += rc; offset += rc;
} }
rc = snprintf(&buf[offset], sizeof buf - (size_t)offset, "[%s] ", rc = snprintf(&buf[offset], sizeof buf - (size_t)offset, "[%s] ",
@@ -367,11 +367,16 @@ static inline void uc_vlog_syslog(const struct uc_log_args *args, const char *fm
if(rc < 0) if(rc < 0)
goto log; goto log;
offset +=rc; offset +=rc;
}
vsnprintf(&buf[offset], sizeof buf - (size_t)offset, fmt, ap);
log: log:
vsnprintf(&buf[offset], sizeof buf - (size_t)offset, fmt, ap);
syslog(pri, "%s", buf); syslog(pri, "%s", buf);
} else { //raw logging
vsyslog(pri, fmt, ap);
}
} }
void uc_logf(int log_level, int module, int raw, void uc_logf(int log_level, int module, int raw,