ApiLog.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //---------------------------------------------------------------------------
  2. #include "stdafx.h"
  3. #include "ApiLog.h"
  4. //////////////////////////////////////////////////////////////////////
  5. // Konstruktion/Destruktion
  6. //////////////////////////////////////////////////////////////////////
  7. CApiLog::CApiLog()
  8. {
  9. FIntern = NULL;
  10. }
  11. CApiLog::~CApiLog()
  12. {
  13. }
  14. void CApiLog::InitIntern(TFileZillaIntern * Intern)
  15. {
  16. FIntern = Intern;
  17. }
  18. TFileZillaIntern * CApiLog::GetIntern()
  19. {
  20. return FIntern;
  21. }
  22. bool CApiLog::LoggingMessageType(int nMessageType) const
  23. {
  24. return
  25. (nMessageType < FZ_LOG_APIERROR) ||
  26. ((nMessageType-FZ_LOG_APIERROR) < FIntern->GetDebugLevel());
  27. }
  28. void CApiLog::LogMessage(int nMessageType, LPCTSTR pMsgFormat, ...) const
  29. {
  30. DebugAssert(nMessageType>=FZ_LOG_STATUS && nMessageType<=FZ_LOG_DEBUG);
  31. if (!LoggingMessageType(nMessageType))
  32. return;
  33. va_list ap;
  34. va_start(ap, pMsgFormat);
  35. CString text;
  36. text.FormatV(pMsgFormat, ap);
  37. va_end(ap);
  38. if (nMessageType>=FZ_LOG_DEBUG)
  39. return;
  40. SendLogMessage(nMessageType, text);
  41. }
  42. void CApiLog::LogMessageRaw(int nMessageType, LPCTSTR pMsg) const
  43. {
  44. DebugAssert(nMessageType>=FZ_LOG_STATUS && nMessageType<=FZ_LOG_DEBUG);
  45. if (!LoggingMessageType(nMessageType))
  46. return;
  47. if (nMessageType>=FZ_LOG_DEBUG)
  48. return;
  49. SendLogMessage(nMessageType, pMsg);
  50. }
  51. void CApiLog::LogMessage(int nMessageType, UINT nFormatID, ...) const
  52. {
  53. DebugAssert(nMessageType>=FZ_LOG_STATUS && nMessageType<=FZ_LOG_DEBUG);
  54. if (!LoggingMessageType(nMessageType))
  55. return;
  56. CString str;
  57. str.LoadString(nFormatID);
  58. va_list ap;
  59. va_start(ap, nFormatID);
  60. CString text;
  61. text.FormatV(str, ap);
  62. va_end(ap);
  63. if (nMessageType>=FZ_LOG_DEBUG)
  64. return;
  65. SendLogMessage(nMessageType, text);
  66. }
  67. void CApiLog::SendLogMessage(int nMessageType, LPCTSTR pMsg) const
  68. {
  69. if (!LoggingMessageType(nMessageType))
  70. return;
  71. //Displays a message in the message log
  72. t_ffam_statusmessage *pStatus = new t_ffam_statusmessage;
  73. pStatus->post = TRUE;
  74. pStatus->status = pMsg;
  75. pStatus->type = nMessageType;
  76. if (!FIntern->PostMessage(FZ_MSG_MAKEMSG(FZ_MSG_STATUS, 0), (LPARAM)pStatus))
  77. delete pStatus;
  78. }
  79. CString CApiLog::GetOption(int OptionID) const
  80. {
  81. DebugAssert(FIntern != NULL);
  82. return FIntern->GetOption(OptionID);
  83. }
  84. int CApiLog::GetOptionVal(int OptionID) const
  85. {
  86. DebugAssert(FIntern != NULL);
  87. return FIntern->GetOptionVal(OptionID);
  88. }