12/4 Is there a way to do a c/c++ log macro/function so that in the log
message it will automatically output the filename/function name
or something of that sort?
\_ One (bad) attempt, just to give you an idea:
#define LOGMSG logMsg(__FILE__, __LINE__,
int logMsg(char *fname, int line, char *msgfmt, ...) {
char msg[512]; va_list vl;
va_start(vl, msgfmt); vsprintf(msg, msgfmt, vl); va_end(vl);
printf("%s:%d : %s", fname, line, msg);
return 0;
}
Macros don't allow varargs, so your uses of this macro are going to
\_ http://docs.freebsd.org/info/gcc/gcc.info.Macro_Varargs.html
\_ that's almost as cool as the shirt folding thing. Thanks.
look like
LOG_MSG "This is error number %d\n", foo);
^ note missing "("
The macro will expand this to
logMsg(__FILE__, __LINE__, "This is error number %d\n", foo);
and your log msg will look like:
myfile.c:104 : This is error number 5
It would be a lot nicer if you could define some standard log formats,
then you wouldn't have to do that horrible horrible macro stuff.
\_ You should use log4cplus. I use it and it's fairly easy to
configure. |