tcpdaemon-1.1.0/ src/ tcpdaemon.h main.c tcpdaemon.c worker.c LOGC.h LOGC.c ...
#include "../src/LOGC.h" int test_logc() { char buf[ 64 + 1 ] ; long buflen ; SetLogFile( "%s/log/test_logc.log" , getenv("HOME") ); SetLogLevel( LOGLEVEL_INFO ); DebugLog( __FILE__ , __LINE__ , "call DebugLog" ); InfoLog( __FILE__ , __LINE__ , "call InfoLog" ); WarnLog( __FILE__ , __LINE__ , "call WarnLog" ); ErrorLog( __FILE__ , __LINE__ , "call ErrorLog" ); FatalLog( __FILE__ , __LINE__ , "call FatalLog" ); memset( buf , 0x00 , sizeof(buf) ); buflen = sizeof(buf) - 1 ; DebugHexLog( __FILE__ , __LINE__ , buf , buflen , "call DebugHexLog" ); InfoHexLog( __FILE__ , __LINE__ , buf , buflen , "call InfoHexLog" ); WarnHexLog( __FILE__ , __LINE__ , buf , buflen , "call WarnHexLog" ); ErrorHexLog( __FILE__ , __LINE__ , buf , buflen , "call ErrorHexLog" ); FatalHexLog( __FILE__ , __LINE__ , buf , buflen , "call FatalHexLog" ); return 0; } int main() { return -test_logc(); }
$ gcc -g -fPIC -O2 -Wall -Werror -fno-strict-aliasing -I. -c test_logc.c $ gcc -g -fPIC -O2 -Wall -Werror -fno-strict-aliasing -I. -c ../src/LOGC.c $ gcc -g -fPIC -O2 -Wall -Werror -fno-strict-aliasing -o test_logc test_logc.o LOGC.o -lpthread $ ./test_logc $ cat $HOME/log/test_logc.log 2014-07-20 22:35:12.890000 | INFO | 1556:3284:test_logc.c:12 | call InfoLog 2014-07-20 22:35:12.906000 | WARN | 1556:3284:test_logc.c:13 | call WarnLog 2014-07-20 22:35:12.906000 | ERROR | 1556:3284:test_logc.c:14 | call ErrorLog 2014-07-20 22:35:12.906000 | FATAL | 1556:3284:test_logc.c:15 | call FatalLog 2014-07-20 22:35:12.906000 | INFO | 1556:3284:test_logc.c:20 | call InfoHexLog 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 2014-07-20 22:35:12.906000 | WARN | 1556:3284:test_logc.c:21 | call WarnHexLog 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 2014-07-20 22:35:12.906000 | ERROR | 1556:3284:test_logc.c:22 | call ErrorHexLog 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 2014-07-20 22:35:12.906000 | FATAL | 1556:3284:test_logc.c:23 | call FatalHexLog 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0x00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
开源纯C日志函数库iLOG3快速入门(八、如果你喜欢简单日志函数甚于日志函数库),布布扣,bubuko.com
开源纯C日志函数库iLOG3快速入门(八、如果你喜欢简单日志函数甚于日志函数库)
原文地址:http://my.oschina.net/u/988092/blog/293142