wrapper printf function that filters according to user preferences

前端 未结 3 942
死守一世寂寞
死守一世寂寞 2021-02-04 01:42

My program writes to a log and to stdout. Every message, however, has a certain priority and the user specifies in Preferences which priorities go to which stream (log or stdout

3条回答
  •  自闭症患者
    2021-02-04 02:25

    I think Jeff's idea is the way to go, but you can also accomplish this with a macro without using vprintf. This might require gcc:

    #define write_log(priority,format,args...)        \
                      if (priority & PRIO_LOG) {      \ 
                          printf(format, ## args);    \
                      }
    

    Check here for info about how this works.

提交回复
热议问题