xLog.Log4CPP.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #pragma once
  2. #include <assert.h>
  3. #include "String.DString.hpp"
  4. #define __X_LOG_LOG4CPP__
  5. //-----------------------------------------------------------------------------
  6. // xLog 是对 gLogger 的简单封装
  7. // xLog 可以理解为 exLog, 或者 extraLog 的短名称
  8. // 某些组件需要写到两个 Logger 中, 可以包含这个 hpp
  9. // 纯粹从 mLog 复制而来
  10. //-----------------------------------------------------------------------------
  11. namespace xLog
  12. {
  13. extern Log4CPP::Logger * gLogger;
  14. inline void NewLine ()
  15. {
  16. if (! gLogger) return;
  17. gLogger->NewLine ();
  18. }
  19. inline eSTR::DString ErrorCodeToString (DWORD errorCode)
  20. {
  21. if (! gLogger) return eSTR::DString ();
  22. return gLogger->ErrorCodeToString (errorCode);
  23. }
  24. template <typename... Args>
  25. inline void Force (const char* fmt, Args && ... args)
  26. {
  27. if (! gLogger) return;
  28. gLogger->Force (fmt, std::forward <Args> (args)...);
  29. }
  30. template <typename... Args>
  31. inline void Log (const char* fmt, Args && ... args)
  32. {
  33. if (! gLogger) return;
  34. gLogger->Info (fmt, std::forward <Args> (args)...);
  35. }
  36. template <typename... Args>
  37. inline void Trace (const char* fmt, Args && ... args)
  38. {
  39. if (! gLogger) return;
  40. gLogger->Trace (fmt, std::forward <Args> (args)...);
  41. }
  42. template <typename... Args>
  43. inline void Debug (const char* fmt, Args && ... args)
  44. {
  45. if (! gLogger) return;
  46. gLogger->Debug (fmt, std::forward <Args> (args)...);
  47. }
  48. template <typename... Args>
  49. inline void Info (const char* fmt, Args && ... args)
  50. {
  51. if (! gLogger) return;
  52. gLogger->Info (fmt, std::forward <Args> (args)...);
  53. }
  54. template <typename... Args>
  55. inline void Notice (const char* fmt, Args && ... args)
  56. {
  57. if (! gLogger) return;
  58. gLogger->Notice (fmt, std::forward <Args> (args)...);
  59. }
  60. template <typename... Args>
  61. inline void Warn (const char* fmt, Args && ... args)
  62. {
  63. if (! gLogger) return;
  64. gLogger->Warn (fmt, std::forward <Args> (args)...);
  65. }
  66. template <typename... Args>
  67. inline void Warning (const char* fmt, Args && ... args)
  68. {
  69. if (! gLogger) return;
  70. gLogger->Warn (fmt, std::forward <Args> (args)...);
  71. }
  72. template <typename... Args>
  73. inline void Error (const char* fmt, Args && ... args)
  74. {
  75. if (! gLogger) return;
  76. gLogger->Error (fmt, std::forward <Args> (args)...);
  77. }
  78. template <typename... Args>
  79. inline void Fatal (const char* fmt, Args && ... args)
  80. {
  81. if (! gLogger) return;
  82. gLogger->Fatal (fmt, std::forward <Args> (args)...);
  83. }
  84. inline void Flush (const eSTR::DStringView & str)
  85. {
  86. if (! gLogger) return;
  87. gLogger->LogNoFormat (Log4CPP::enInfo, str, str.GetLength (), false);
  88. }
  89. inline void Flush (const eSTR::DString & str)
  90. {
  91. if (! gLogger) return;
  92. gLogger->LogNoFormat (Log4CPP::enInfo, str, str.GetLength (), false);
  93. }
  94. inline void Flush (const char * str, int len)
  95. {
  96. if (! gLogger) return;
  97. gLogger->LogNoFormat (Log4CPP::enInfo, str, len, false);
  98. }
  99. inline void LogNoFormat (int Level, const eSTR::DString & str, bool bWithLayout = false)
  100. {
  101. if (! gLogger) return;
  102. gLogger->LogNoFormat (Level, str, str.GetLength (), bWithLayout);
  103. }
  104. inline void LogNoFormat (int Level, const char* buf, int len, bool bWithLayout = false)
  105. {
  106. if (! gLogger) return;
  107. gLogger->LogNoFormat (Level, buf, len, bWithLayout);
  108. }
  109. inline bool Decide (int Level)
  110. {
  111. if (! gLogger) return false;
  112. return (gLogger->Decide (Level));
  113. }
  114. inline void Close ()
  115. {
  116. if (! gLogger) return;
  117. gLogger->Close ();
  118. }
  119. };