Berkeley CSUA MOTD:Entry 11316
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2003/12/4-5 [Computer/SW/Languages/C_Cplusplus] UID:11316 Activity:nil
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.
2025/05/24 [General] UID:1000 Activity:popular
5/24    

You may also be interested in these entries...
2008/4/15-23 [Computer/Companies/Google] UID:49755 Activity:high
4/15    Anyone got any random investment tips? I am kinda at a loss of what to do.
        Agriculture and energy are at record highs...
        \_ stockhouse.ca .. NOT - via NOSOF ... assay results coming in soon
        \_ I'm liking HRP, currently paying 12.2% dividend; there's some
           risk, but they shouldn't be as exposed to some of the macro
           issues as a lot of stocks.  Ex-div is coming up next week.
	...
Cache (472 bytes)
docs.freebsd.org/info/gcc/gcc.info.Macro_Varargs.html
All of them plus the commas between them form the value of args, which is substituted into the macro body where args is used. Thus, we have this expansion: eprintf s:d: , input_file_name, line_number > fprintf stderr, s:d: , input_file_name, line_number Note that the comma after the string constant comes from the definition of eprintf, whereas the last comma comes from the value of args. The reason for using is to handle the case when args matches no arguments at all.