mgLog最简单的使用
在不指定输出函数时,其将指定输出到标准输出设备中去
代码如下
int main(int argc, char **argv)
{
mglog_level(MG_LOG_DEBUG, "This is test %s, %d\n", "DEBUG", 1);
mglog_level(MG_LOG_TRACE, "This is test %s, %d\n", "trace", 2);
mglog_level(MG_LOG_MSG, "This is test %s, %d\n", "msg", 3);
mglog_level(MG_LOG_WARN, "This is test %s, %d\n", "warn", 4);
mglog_level(MG_LOG_ERR, "This is test %s, %d\n", "err", 5);
mglog_level(MG_LOG_ERR+1, "This is test %s, %d\n", "unkonw", 6);
mglog_debug("This is log test %s, %d\n", "lDebug", 11);
mglog_msg("this is log test %s, %d\n", "lmsg", 12);
mglog_warn("this is log test %s, %d\n", "lwarn", 13);
mglog_err("This is log test %s, %d\n", "lerr", 14);
mglog_other("HAHA", "This is other test %s, %d\n", "haha", 21);
mglog_other("HOHO", "This is ohter test %s, %d", "hoho", 22);
mglog_trace_x("Nofile", 33232, "mglog_trace_x", "This is trace test %s, %d", "xtrace", 31);
mglog_trace("This is trace test %s, %d", "ltrace", 41);
return 0;
}
输出结果如下
[root@localhost src]$ ./mgLogtest
[DEBUG] This is test DEBUG, 1
[TRACE] This is test trace, 2
[MSG] This is test msg, 3
[WARN] This is test warn, 4
[ERR] This is test err, 5
[UNKNOW] This is test unkonw, 6
[DEBUG] This is log test lDebug, 11
[MSG] this is log test lmsg, 12
[WARN] this is log test lwarn, 13
[ERR] This is log test lerr, 14
[HAHA] This is other test haha, 21
[HOHO] This is ohter test hoho, 22
[TRACE] <Nofile:33232(mglog_trace_x)[16688]>This is trace test xtrace, 31
[TRACE] <mgLogtest.c:34(main)[16688]>This is trace test ltrace, 41
其中需要说明的是trace模式
mglog_trance是标准的,基含义为:[日志模式]<文件名:行号(函数)[进程号]>