FrmSysLogF.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. reMsg->Lines->Clear();
  88. #endif
  89. reMsg->Lines->Add(ALog->Tm.FormatString("hh:nn:ss") + "." + Now().FormatString("ss") + sLogKind + String(ALog->Msg));
  90. //reMsg->Lines->Add(ALog->Tm.FormatString("hh:nn:ss") + "." + Now().FormatString("ss") + String(ALog->Msg));
  91. //reMsg->Lines->Add(ALog->Tm.FormatString("hh:nn:ss") + "[" + Now().FormatString("ss") + "]" + String(ALog->Msg));
  92. Application->ProcessMessages();
  93. }
  94. catch(Exception &e)
  95. {
  96. }
  97. }
  98. __finally
  99. {
  100. //reMsg->Lines->EndUpdate();
  101. //SendMessage(reMsg->Handle, EM_SCROLLCARET, 0, 0);
  102. //reMsg->Perform(EM_SCROLLCARET, 0, 0);
  103. //Application->ProcessMessages();
  104. }
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TFrmSysLog::FormShow(TObject *Sender)
  108. {
  109. Application->ProcessMessages();
  110. reMsg->Lines->Add( Now().FormatString("hh:nn:ss") + "." + Now().FormatString("ss") + " ***** Starting program...");
  111. }
  112. //---------------------------------------------------------------------------
  113. void TFrmSysLog::DisplayMsg(String& AMsg)
  114. {
  115. if (chkLogPause->Checked) return;
  116. if (!Showing) return;
  117. if (reMsg->Lines->Count >= g_AppCfg.nMaxLogLines)
  118. reMsg->Lines->Clear();
  119. if (AMsg != "")
  120. {
  121. AMsg[AMsg.Length()-1] = 0; // 마지막줄의 CRLF 삭제. 그래야 메모장에서는 줄간 간격이 떨어지지 않게 찍힌다.
  122. reMsg->Lines->Add(AMsg);
  123. }
  124. }
  125. //---------------------------------------------------------------------------