tLog.Log4CPP.hpp 3.3 KB

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