CommLogF.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //---------------------------------------------------------------------------
  2. #ifndef CommLogFH
  3. #define CommLogFH
  4. //---------------------------------------------------------------------------
  5. #include <windows.h>
  6. #include <SyncObjs.hpp>
  7. #include <stdio.h>
  8. //---------------------------------------------------------------------------
  9. #define LOG_DISPLAY_FIRST 1
  10. #define MAX_LOG_BUFFER 2048
  11. // 로그 종류
  12. typedef enum eEN_LOG_KIND
  13. {
  14. eLOG_NONE = 0x00, /* 없음 */
  15. eLOG_INFO = 0x01, /* 정보 */
  16. eLOG_DATA = 0x02, /* 데이터 */
  17. eLOG_ERROR = 0x04, /* 에러 */
  18. eLOG_WARNING = 0x08, /* 경고 */
  19. eLOG_DEBUG = 0x10, /* 디버그 */
  20. eLOG_DETAIL = 0x1F /* 상세 */
  21. } EN_LOG_KIND;
  22. typedef struct tagLogInfo
  23. {
  24. bool Info;
  25. bool Data;
  26. bool Error;
  27. bool Warning;
  28. bool Debug;
  29. bool Detail;
  30. public:
  31. tagLogInfo()
  32. {
  33. Info = true;
  34. Data = false;
  35. Error = true;
  36. Warning = true;
  37. Debug = false;
  38. Detail = false;
  39. }
  40. } LOG_INFO;
  41. typedef struct tagLogMessage
  42. {
  43. int Kind; /* message kind */
  44. int Len; /* message len */
  45. // TDateTime Tm; /* message create time */
  46. char Data[MAX_LOG_BUFFER]; /* message data */
  47. } LOG_MESSAGE;
  48. //---------------------------------------------------------------------------
  49. #define LOGINFO(args...) CommLog->LogWrite(NULL, eLOG_INFO, ##args)
  50. #define LOGDATA(args...) CommLog->LogWrite(NULL, eLOG_DATA, ##args)
  51. #define LOGERROR(args...) CommLog->LogWrite(NULL, eLOG_ERROR, ##args)
  52. #define LOGWARN(args...) CommLog->LogWrite(NULL, eLOG_WARNING, ##args)
  53. #define LOGDEBUG(args...) CommLog->LogWrite(NULL, eLOG_DEBUG, ##args)
  54. //---------------------------------------------------------------------------
  55. #define DBERRORMSG(v,w,x,y) CommLog->LogDbError(v,w,x,y,__FILE__, String(__FUNC__), __LINE__,true)
  56. #define DBERRORLOG(v,w,x,y) CommLog->LogDbError(v,w,x,y,__FILE__, String(__FUNC__), __LINE__,false)
  57. //---------------------------------------------------------------------------
  58. class TCommLog
  59. {
  60. public:
  61. TCommLog(String ALogDir, String ALogName, String ALogDay);
  62. ~TCommLog();
  63. protected:
  64. public:
  65. String FLogDay;
  66. String FLogFile;
  67. void SendLogMessage(int AKind, char *AFmt, ...);
  68. FILE *OpenLogFile(AnsiString AFileExt=".log");
  69. int LogData(char *ASndRcv, const unsigned char *AData, int ALen, FILE *Afp=NULL);
  70. int LogWrite(FILE *Afp, int ALogKind, char *AFmt, ...);
  71. int LogDbError(String ATitle, String AClass, String AError, String ASql,
  72. String AFile, String AFunc, int ALine, bool AShowMsg=true);
  73. };
  74. //---------------------------------------------------------------------------
  75. extern PACKAGE TCommLog *CommLog;
  76. extern LOG_INFO g_LogCfg;
  77. //---------------------------------------------------------------------------
  78. #endif