testlog4c.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // testlog4c.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. //#include "Log.h"
  5. //using namespace SToneULog;
  6. #pragma comment(lib,"Log4C.lib")
  7. int _tmain(int argc, _TCHAR* argv[])
  8. {
  9. //LOG4C_INIT_DEFAULT();
  10. //LOG_PARAM *pLogParam = new LOG_PARAM[sizeof(LOG_PARAM)];
  11. //LOG4C((pLogParam, LOG_ERROR, "Hello World!"));
  12. //if( NULL != pLogParam )
  13. //{
  14. // delete[] pLogParam;
  15. // pLogParam = NULL;
  16. //}
  17. //char strBuffer[128] = "You are the Best One!\0 Yes.";
  18. //LOG4C_HEX_DUMP(( LOG_TRACE, strBuffer, sizeof(strBuffer)));
  19. #if 1 // 是否使用默认
  20. LOG4C_INIT_DEFAULT();
  21. #else
  22. char szFileName[MAX_PATH];
  23. sprintf(szFileName, "%s\\log4crc", g_strDirectory);
  24. ///设置日志配置文件名
  25. LOG4C_PARAM_CFG_FILE_NAME(szFileName);
  26. ///设置日志级别
  27. LOG4C_PARAM_LOG_LEVEL("unknown");
  28. ///设置日志文件大小
  29. LOG4C_PARAM_LOG_FILE_SIZE(10240);
  30. ///设置生成日志文件个数,达到最大个数将自动覆盖最旧的日志
  31. LOG4C_PARAM_LOG_FILE_NUM(5);
  32. ///设置每次记录日志都重新读取日志配置文件
  33. LOG4C_PARAM_REREAD_LOG_CFG_FILE(1);
  34. ///带参数日志模块初始化,以上所有设置了的参数都将生效,没有设置的采用缺省值
  35. LOG4C_INIT_WITH_PARAM();
  36. #endif
  37. LOG4C_BLOCK_BEGIN(("LOG4C_BLOCK_BEGIN0"));
  38. LOG4C_BLOCK_BEGIN(("LOG4C_BLOCK_BEGIN1"));
  39. LOG4C_BLOCK_BEGIN(("LOG4C_BLOCK_BEGIN2"));
  40. LOG4C_BLOCK_BEGIN(("LOG4C_BLOCK_BEGIN3"));
  41. LOG4C_BLOCK_END(("LOG4C_BLOCK_BEGIN3"));
  42. LOG4C_BLOCK_END(("LOG4C_BLOCK_BEGIN2"));
  43. LOG4C_BLOCK_END(("LOG4C_BLOCK_BEGIN1"));
  44. LOG4C_BLOCK_END(("LOG4C_BLOCK_BEGIN0"));
  45. char strBuffer[128] = "You are the Best One!\0 Yes.";
  46. LOG4C_HEX_DUMP((LOG_INFO, strBuffer, sizeof(strBuffer)));
  47. LOG4C_ORIGIN ((LOG_ERROR,"LOG4C_ORIGIN"));
  48. LOG4C_NO_FILENUM((LOG_ERROR, "LOG4C_NO_FILENUM"));
  49. //LOG4C_RETURN_WITH_VALUE(( LOG4C_PRIORITY_TRACE, "message"), 1);
  50. LOG4C_FUN(("Hello World!"));
  51. LOG4C((LOG_ERROR, "Hello World!"));
  52. LOG4C_IF((4>3, LOG_ERROR, "LOG4C_IF:4>3"));
  53. LOG4C_IF((2>3, LOG_ERROR, "LOG4C_IF:2>3"));
  54. LOG4C_LINE();
  55. LOG4C_FINI();
  56. #if 0
  57. int rc = 0;
  58. if (log4c_init())
  59. {
  60. //printf("log4c_init() failed");
  61. rc = 1;
  62. }
  63. else
  64. {
  65. g_pRoot = log4c_category_get("root");
  66. //log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "Hello World!");
  67. //log4c_category_error(mycat, "you know error!");
  68. LOG4C("Hello World!");
  69. LOG4C("%s", "you know error!");
  70. /* Explicitly call the log4c cleanup routine */
  71. if ( log4c_fini())
  72. {
  73. printf("log4c_fini() failed");
  74. }
  75. }
  76. #endif
  77. return 0;
  78. }