FrmSysLogF.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FrmSysLogF.h"
  5. #include "VMSCommLibF.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TFrmSysLog *FrmSysLog = NULL;
  10. //---------------------------------------------------------------------------
  11. __fastcall TFrmSysLog::TFrmSysLog(TComponent* Owner)
  12. : TForm(Owner)
  13. {
  14. reMsg->Lines->Clear();
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TFrmSysLog::btnClearClick(TObject *Sender)
  18. {
  19. try
  20. {
  21. reMsg->Lines->Clear();
  22. Application->ProcessMessages();
  23. }
  24. catch(Exception &e)
  25. {
  26. }
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TFrmSysLog::btnCopyClick(TObject *Sender)
  30. {
  31. try
  32. {
  33. reMsg->SelectAll();
  34. reMsg->CopyToClipboard();
  35. Application->ProcessMessages();
  36. }
  37. catch(Exception &e)
  38. {
  39. }
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TFrmSysLog::OnWMLogDisplayMessage(TMessage &Msg)
  43. {
  44. if (chkLogPause->Checked) return;
  45. IPC_LOG_MESSAGE *pLog = (IPC_LOG_MESSAGE *)Msg.WParam;
  46. if (pLog)
  47. {
  48. #if 0
  49. IPC_LOG_MESSAGE Log;
  50. Log.Kind = pLog->Kind;
  51. Log.Flag = pLog->Flag;
  52. Log.Len = pLog->Len;
  53. Log.Tm = pLog->Tm;
  54. memcpy(Log.Msg, pLog->Msg, sizeof(Log.Msg));
  55. //ReplyMessage(0);
  56. LogWrite(&Log);
  57. #else
  58. ReplyMessage(0);
  59. LogWrite(pLog);
  60. #endif
  61. }
  62. }
  63. //---------------------------------------------------------------------------
  64. void TFrmSysLog::LogWrite(IPC_LOG_MESSAGE *ALog)
  65. {
  66. if (!ALog) return;
  67. try
  68. {
  69. //reMsg->Lines->BeginUpdate();
  70. AnsiString sLogKind = " [XXX] ";
  71. switch(ALog->Kind)
  72. {
  73. case eLOG_INFO : sLogKind = " [INF] "; break;
  74. case eLOG_DATA : sLogKind = " [DAT] "; break;
  75. case eLOG_ERROR : sLogKind = " [ERR] "; break;
  76. case eLOG_WARNING: sLogKind = " [WAN] "; break;
  77. case eLOG_DEBUG : sLogKind = " [DBG] "; break;
  78. case eLOG_DETAIL : sLogKind = " [DET] "; break;
  79. }
  80. try
  81. {
  82. #if 0
  83. while (reMsg->Lines->Count >= g_AppCfg.nMaxLogLines)
  84. reMsg->Lines->Delete(0);
  85. #else
  86. if (reMsg->Lines->Count >= g_AppCfg.nMaxLogLines)
  87. {
  88. reMsg->Lines->Clear();
  89. }
  90. #endif
  91. reMsg->Lines->Add(ALog->Tm.FormatString("hh:nn:ss") + "." + Now().FormatString("ss") + sLogKind + String(ALog->Msg));
  92. //reMsg->Lines->Add(ALog->Tm.FormatString("hh:nn:ss") + "." + Now().FormatString("ss") + String(ALog->Msg));
  93. //reMsg->Lines->Add(ALog->Tm.FormatString("hh:nn:ss") + "[" + Now().FormatString("ss") + "]" + String(ALog->Msg));
  94. Application->ProcessMessages();
  95. }
  96. catch(Exception &e)
  97. {
  98. }
  99. }
  100. __finally
  101. {
  102. //reMsg->Lines->EndUpdate();
  103. //SendMessage(reMsg->Handle, EM_SCROLLCARET, 0, 0);
  104. //reMsg->Perform(EM_SCROLLCARET, 0, 0);
  105. //Application->ProcessMessages();
  106. }
  107. }
  108. //---------------------------------------------------------------------------
  109. void __fastcall TFrmSysLog::FormShow(TObject *Sender)
  110. {
  111. Application->ProcessMessages();
  112. reMsg->Lines->Add( Now().FormatString("hh:nn:ss") + "." + Now().FormatString("ss") + " ***** Starting program...");
  113. }
  114. //---------------------------------------------------------------------------
  115. void TFrmSysLog::DisplayMsg(String& AMsg)
  116. {
  117. if (chkLogPause->Checked) return;
  118. if (!Showing) return;
  119. if (reMsg->Lines->Count >= g_AppCfg.nMaxLogLines)
  120. reMsg->Lines->Clear();
  121. if (AMsg != "")
  122. {
  123. AMsg[AMsg.Length()-1] = 0; // 마지막줄의 CRLF 삭제. 그래야 메모장에서는 줄간 간격이 떨어지지 않게 찍힌다.
  124. reMsg->Lines->Add(AMsg);
  125. }
  126. }
  127. //---------------------------------------------------------------------------