ITSLogF.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #if !defined(__ITSLog_DLL_H__)
  2. #define __ITSLog_DLL_H__
  3. #include <vcl.h>
  4. #include <Classes.hpp>
  5. #include <math.h>
  6. #include <map>
  7. #include <vector>
  8. #include <list>
  9. #include <algorithm>
  10. #include <windows.h>
  11. #include <SyncObjs.hpp>
  12. #include <stdio.h>
  13. /*
  14. *****************************************************************************
  15. * DLL Import/Export
  16. *****************************************************************************
  17. */
  18. #ifdef __ITSLog_DLL_EXPORT__
  19. #define ITSLog_LIB __declspec(dllexport)
  20. #else
  21. #define ITSLog_LIB __declspec(dllimport)
  22. //#pragma comment(lib, "ITSLog.lib") /* 동적으로 dll 로딩할때 사용한다. */
  23. #endif
  24. /*
  25. *****************************************************************************
  26. * Defines
  27. *****************************************************************************
  28. */
  29. #define MAX_LOG_BUFFER 4096
  30. typedef enum eEN_LOG_KIND
  31. {
  32. eLOG_NONE = 0x00, /* 없음 */
  33. eLOG_INFO = 0x01, /* 정보 */
  34. eLOG_DATA = 0x02, /* 데이터 */
  35. eLOG_ERROR = 0x04, /* 에러 */
  36. eLOG_WARNING = 0x08, /* 경고 */
  37. eLOG_DEBUG = 0x10, /* 디버그 */
  38. eLOG_DETAIL = 0x1F /* 상세 */
  39. } EN_LOG_KIND;
  40. typedef struct tagLogInfo
  41. {
  42. bool Info;
  43. bool Data;
  44. bool Error;
  45. bool Warning;
  46. bool Debug;
  47. bool Detail;
  48. public:
  49. tagLogInfo()
  50. {
  51. Info = true;
  52. Data = false;
  53. Error = true;
  54. Warning = true;
  55. Debug = false;
  56. Detail = false;
  57. }
  58. } LOG_INFO;
  59. typedef struct tagLogMessage
  60. {
  61. int Kind; /* message kind */
  62. int Len; /* message len */
  63. TDateTime Tm; /* message create time */
  64. char Data[MAX_LOG_BUFFER]; /* message data */
  65. } LOG_MESSAGE;
  66. //---------------------------------------------------------------------------
  67. #define LOGINFO(args...) ITSLog->LogWrite(NULL, eLOG_INFO, ##args)
  68. #define LOGDATA(args...) ITSLog->LogWrite(NULL, eLOG_DATA, ##args)
  69. #define LOGERROR(args...) ITSLog->LogWrite(NULL, eLOG_ERROR, ##args)
  70. #define LOGWARN(args...) ITSLog->LogWrite(NULL, eLOG_WARNING, ##args)
  71. #define LOGDEBUG(args...) ITSLog->LogWrite(NULL, eLOG_DEBUG, ##args)
  72. //---------------------------------------------------------------------------
  73. #define DBERRORMSG(v,w,x,y) ITSLog->LogDbError(v,w,x,y,__FILE__, String(__FUNC__), __LINE__,true)
  74. #define DBERRORLOG(v,w,x,y) ITSLog->LogDbError(v,w,x,y,__FILE__, String(__FUNC__), __LINE__,false)
  75. /*
  76. * ITS Log class
  77. */
  78. class ITSLog_LIB __stdcall TITSLog
  79. {
  80. private:
  81. CRITICAL_SECTION CS;
  82. public:
  83. TITSLog(String ALogDir, String ALogName, String ALogDay, bool ABackup=false);
  84. ~TITSLog();
  85. public:
  86. LOG_INFO FLogCfg;
  87. String FLogDay;
  88. String FErrLogDay;
  89. String FLogFile;
  90. public:
  91. void SendLogMessage(int AKind, char *AFmt, ...);
  92. FILE *OpenLogFile(AnsiString AFileExt=".log");
  93. int LogData(char *ASndRcv, const unsigned char *AData, int ALen, FILE *Afp=NULL);
  94. int LogWrite(FILE *Afp, int ALogKind, char *AFmt, ...);
  95. int LogDbError(String ATitle, String AClass, String AError, String ASql,
  96. String AFile, String AFunc, int ALine, bool AShowMsg=true);
  97. int LogDbInfo(String ATitle, String ASql);
  98. };
  99. //---------------------------------------------------------------------------
  100. //---------------------------------------------------------------------------
  101. /*
  102. *****************************************************************************
  103. * Function Prototypes
  104. *****************************************************************************
  105. */
  106. extern "C"
  107. {
  108. ITSLog_LIB TITSLog* __stdcall ITSLog_Initialize(String ALogDir, String ALogName, String ALogDay);
  109. ITSLog_LIB int __stdcall ITSLog_SetConfig(LOG_INFO &ALogCfg);
  110. ITSLog_LIB int __stdcall ITSLog_Term();
  111. } /* extern "C" */
  112. #endif /* __ITSLog_DLL_H__ */