From 53c2d0e3d9419f4c4217031c631421ff9ee7e940 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 11 Nov 2019 18:52:00 +0100 Subject: [PATCH] Export flog() function and define new log macros ERR(), WARN(), etc. Signed-off-by: Joachim Nilsson --- src/syslogd.c | 3 +-- src/syslogd.h | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/syslogd.c b/src/syslogd.c index fc90c40..0976dcd 100644 --- a/src/syslogd.c +++ b/src/syslogd.c @@ -159,7 +159,6 @@ void wallmsg(struct filed *f, struct iovec *iov, int iovcnt); void reapchild(); const char *cvtaddr(struct sockaddr_storage *f, int len); const char *cvthname(struct sockaddr_storage *f, int len); -static void flog(int pri, char *fmt, ...); void domark(); void debug_switch(); void logerror(const char *type); @@ -2008,7 +2007,7 @@ const char *cvthname(struct sockaddr_storage *f, int len) /* * Base function for domark(), logerror(), etc. */ -static void flog(int pri, char *fmt, ...) +void flog(int pri, char *fmt, ...) { struct buf_msg buffer; va_list ap; diff --git a/src/syslogd.h b/src/syslogd.h index 1aeaa6c..8f45e6c 100644 --- a/src/syslogd.h +++ b/src/syslogd.h @@ -112,6 +112,13 @@ #define NELEMS(array) (sizeof(array) / sizeof(array[0])) #endif +/* Helper internal log macros */ +#define ERR(fmt, args...) flog(LOG_SYSLOG | LOG_ERR, fmt ": %m", ##args) +#define ERRX(fmt, args...) flog(LOG_SYSLOG | LOG_ERR, fmt, ##args) +#define WARN(fmt, args...) flog(LOG_SYSLOG | LOG_WARN, fmt, ##args) +#define NOTE(fmt, args...) flog(LOG_SYSLOG | LOG_NOTICE, fmt, ##args) +#define INFO(fmt, args...) flog(LOG_SYSLOG | LOG_INFO, fmt, ##args) + /* * Flags to logmsg(). */ @@ -215,4 +222,6 @@ struct filed { int f_rotatesz; }; +void flog(int pri, char *fmt, ...); + #endif /* SYSKLOGD_SYSLOGD_H_ */