int ret = log4c_init(); if (ret) printf("log4c_init() failed\n"); log4c_category_t* mycat = log4c_category_get("log4ctest"); log4c_category_log(mycat, LOG4C_PRIORITY_DEBUG, "Hello World!"); /* Explicitly call the log4c cleanup routine */ if ( log4c_fini()){ printf("log4c_fini() failed\n"); }
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE log4c SYSTEM ""> <log4c version="1.2.4"> <!-- 版本号一定要和log4c的版本相同,否则会初始化失败 --> <config> <bufsize>0</bufsize> <debug level="2"/> <nocleanup>0</nocleanup> <reread>1</reread> </config> <category name="root" priority="notice"/> <category name="light-pg.com" priority="debug" appender="stderr" /> <category name="log4ctest" priority="debug" appender="myrollingfileappender" /> <rollingpolicy name="myrollingpolicy" type="sizewin" maxsize="104857600" maxnum="10" /> <!--sizewin 表示达到最大值后新建日志文件 值由maxsize设定 maxnum 最大文件数目 --> <appender name="myrollingfileappender" type="rollingfile" logdir="./" prefix="mylogfile" layout="dated" rollingpolicy="myrollingpolicy" /> <!--logdir 日志输出路径 prefix 文件名 layout 输出格式 (与下方layout对应) 例如dated为: 20110727 09:21:10.167 WARN log4ctest- [ main.c][ 57][ main()]: shit!-99947 20110727 09:21:10.167 WARN log4ctest- [ main.c][ 57][ main()]: shit!-99948 20110727 09:21:10.167 WARN log4ctest- [ main.c][ 57][ main()]: shit!-99949 basic为: WARN log4ctest - [ main.c][ 57][ main()]: shit!-99982 WARN log4ctest - [ main.c][ 57][ main()]: shit!-99983 WARN log4ctest - [ main.c][ 57][ main()]: shit!-99984 WARN log4ctest - [ main.c][ 57][ main()]: shit!-99985 --> <appender name="stdout" type="stream" layout="basic"/> <appender name="stderr" type="stream" layout="dated"/> <appender name="syslog" type="syslog" layout="basic"/> <appender name="s13file" type="s13_file" layout="basic"/> <appender name="plain_stderr" type="s13_stderr" layout="none"/> <appender name="cat_stderr" type="s13_stderr" layout="catlayout"/> <appender name="xml_stderr" type="s13_stderr" layout="xmllayout"/> <appender name="user_stderr" type="s13_stderr" layout="userlayout"/> <layout name="basic" type="basic"/> <layout name="dated" type="dated"/> <layout name="catlayout" type="s13_cat"/> <layout name="xmllayout" type="s13_xml"/> <layout name="none" type="s13_none"/> <layout name="userlayout" type="s13_userloc"/> </log4c>
虽然说log4c存在内存泄露问题,但是它是少有的纯c编写的日志库,也支持和log4j一样的xml配置。
最后,对于c,推荐zlog或log.c,对于c++,推荐spdlog。
https://reposhub.com/cpp-logging?sort_by=star
https://blog.csdn.net/weixin_44498318/article/details/115207476 c/c++日志库比较
https://blog.csdn.net/yasi_xi/article/details/18356393 几种C/C++ log库的比较
https://blog.51cto.com/u_6043682/3765525 开源日志库 [log4c] 使用
https://log4c.sourceforge.net/index.html
https://www.cnblogs.com/wangkangluo1/archive/2011/07/27/2118667.html log4crc配置文件
https://www.cnblogs.com/jyli/archive/2010/02/11/1660606.html log4c使用
标签:category,配置,html,log4c,https,使用,net,com From: https://www.cnblogs.com/lightdb/p/17020335.html