I am trying to write a function which will take a priority level and a variable amount of strings as arguments to log information in an application.
The function looks something like this so far:
int _logf(int priority, char *fmt, ...)
{
if (log.priority >= priority) {
syslog(priority, "LOG:%s", fmt);
}
/* stderr and syslog */
}
log.priority
is an int
set at run time which could be LOG_INFO
/ LOG_DEBUG
/ LOG_ERR
and in use:
_logf(LOG_INFO, "Starting app version %s", "1.0");
Is this an acceptable way to send log messages to syslog
?
This won't work as you do not involve the variable number of parameters possibly passed into your function.
On how to do this you might take a look a the following example using
vsyslog()
:Then call it for example like so:
Update:
To additionally log to
stderr
you might like to look ath functionvfprintf()
.