#include <stdarg.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <string.h>
/* Note, on my machine strerror_r does not return int nor does it
* fill the passed-in buffer, so I had to use strerror();
*/
void log_debug(const char* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf(stdout, fmt, ap);
fprintf(stdout, "\n");
vsyslog(LOG_DEBUG, fmt, ap);
va_end(ap);
}
void log_info(const char* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf(stdout, fmt, ap);
fprintf(stdout, "\n");
vsyslog(LOG_INFO, fmt, ap);
va_end(ap);
}
void log_errno(const char* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf(stderr, fmt, ap);
vsyslog(LOG_ERR, fmt, ap);
va_end(ap);
char* error_buf = strerror(errno);
syslog(LOG_ERR, error_buf);
fprintf(stderr, ": ");
fprintf(stderr, error_buf);
fprintf(stderr, "\n");
}
void log_error(const char* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
vsyslog(LOG_ERR, fmt, ap);
va_end(ap);
}
void log_hack(const char* fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
vsyslog(LOG_ALERT, fmt, ap);
va_end(ap);
}
--
MattWalsh - 08 Mar 2006