varargs doesn't depend on the format string being the last parameter.
Code:
#include <stdio.h>
#include <stdarg.h>
void __attribute__ ((format (printf, 2, 5)))
log(char *app, char *msg, char *user, int flag, ... )
{
va_list ap;
va_start(ap,flag);
printf("App=%s, user=%s, flag=%d\n",app,user,flag);
vprintf(msg,ap);
printf("\n");
va_end(ap);
}
int main()
{
log("main", "Hey %s %d", "me", 42, "A message", 1234 );
return 0;
}
If you're using gcc, then you'll want to keep the __attribute__ thing so that you get free checking of the variable parameters (just like if you were using regular printf).