1、常用日志模块代码: syslog() , vsyslog()
#include <syslog.h>
#include <stdarg.h>
static void log( const char* func, int line, int priority, char* format, ... )
{
char new_format[255];
snprintf( new_format, sizeof(new_format), "%s:%d: %s: %s", __FILE__, line, func, format );
va_list args;
va_start( args, format );
vsyslog( priority, new_format, args );
va_end( args );
}
#define LOGNAME __FILE__ ": "
#define NOTICE(...) syslog( LOG_NOTICE, LOGNAME __VA_ARGS__ )
#define DEBUG(...) log( __func__, __LINE__, LOG_DEBUG, __VA_ARGS__ )
void test_log(){
openlog("MyMsgMARK", LOG_CONS | LOG_PID, 0);
// syslog(LOG_DEBUG,__func__,"TTTTT");
NOTICE("TTTTTTTTTTTTTTTTTT");
DEBUG("AAAAAAA");
closelog();
return 0;
}