This patch reworks the xlog logging code to avoid rebuilding the message into a
fixed size buffer. It also adds two new logging functions xlog_warn and
xlog_err which are replacements for idmap_warn and idmap_err. There use to be
two different variates of these functions with the only difference being that
one flavor tacked on the error string to the end of the message. This
responsibility has been pushed to the called of the function since it
needlessly complicated the function and required us to rebuild the message
strings.
Signed-off-by: David P. Quigley <dpquigl@tycho.nsa.gov>
Signed-off-by: Kevin Coffman <kwc@citi.umich.edu>
Signed-off-by: Neil Brown <neilb@suse.de>
#ifndef XLOG_H
#define XLOG_H
#ifndef XLOG_H
#define XLOG_H
/* These are logged always. L_FATAL also does exit(1) */
#define L_FATAL 0x0100
#define L_ERROR 0x0200
/* These are logged always. L_FATAL also does exit(1) */
#define L_FATAL 0x0100
#define L_ERROR 0x0200
void xlog_sconfig(char *, int on);
int xlog_enabled(int fac);
void xlog(int fac, const char *fmt, ...);
void xlog_sconfig(char *, int on);
int xlog_enabled(int fac);
void xlog(int fac, const char *fmt, ...);
+void xlog_warn(const char *fmt, ...);
+void xlog_err(const char *fmt, ...);
+void xlog_backend(int fac, const char *fmt, va_list args);
/* Write something to the system logfile and/or stderr */
void
/* Write something to the system logfile and/or stderr */
void
-xlog(int kind, const char *fmt, ...)
+xlog_backend(int kind, const char *fmt, va_list args)
- char buff[1024];
- va_list args;
- int n;
-
if (!(kind & (L_ALL)) && !(logging && (kind & logmask)))
return;
if (!(kind & (L_ALL)) && !(logging && (kind & logmask)))
return;
- va_start(args, fmt);
- vsnprintf(buff, sizeof (buff), fmt, args);
- va_end(args);
-
- if ((n = strlen(buff)) > 0 && buff[n-1] == '\n')
- buff[--n] = '\0';
-
if (log_syslog) {
switch (kind) {
case L_FATAL:
if (log_syslog) {
switch (kind) {
case L_FATAL:
- syslog(LOG_ERR, "%s", buff);
+ vsyslog(LOG_ERR, fmt, args);
- syslog(LOG_ERR, "%s", buff);
+ vsyslog(LOG_ERR, fmt, args);
- syslog(LOG_WARNING, "%s", buff);
+ vsyslog(LOG_WARNING, fmt, args);
- syslog(LOG_NOTICE, "%s", buff);
+ vsyslog(LOG_NOTICE, fmt, args);
break;
default:
if (!log_stderr)
break;
default:
if (!log_stderr)
- syslog(LOG_INFO, "%s", buff);
+ vsyslog(LOG_INFO, fmt, args);
time(&now);
tm = localtime(&now);
time(&now);
tm = localtime(&now);
- fprintf(stderr, "%s[%d] %04d-%02d-%02d %02d:%02d:%02d %s\n",
+ fprintf(stderr, "%s[%d] %04d-%02d-%02d %02d:%02d:%02d ",
log_name, log_pid,
tm->tm_year+1900, tm->tm_mon + 1, tm->tm_mday,
log_name, log_pid,
tm->tm_year+1900, tm->tm_mon + 1, tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec,
- buff);
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
- fprintf(stderr, "%s: %s\n", log_name, buff);
+ fprintf(stderr, "%s: ", log_name);
+
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
}
if (kind == L_FATAL)
exit(1);
}
}
if (kind == L_FATAL)
exit(1);
}
+
+void
+xlog(int kind, const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ xlog_backend(kind, fmt, args);
+ va_end(args);
+}
+
+void
+xlog_warn(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ xlog_backend(L_WARNING, fmt, args);
+ va_end(args);
+}
+
+
+void
+xlog_err(const char* fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ xlog_backend(L_FATAL, fmt, args);
+ va_end(args);
+}