htrace.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /**************************************************************************
  2. *
  3. * Licensed Materials - Property of IBM and/or HCL
  4. *
  5. * IBM Informix Dynamic Server
  6. * Copyright IBM Corporation 1996, 2016
  7. * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
  8. *
  9. ******************************************************************************
  10. */
  11. #include <stdarg.h>
  12. /*
  13. * TRACING MODES OR FLAGS:
  14. * With heavy tracing there are 3 functions that the programmer uses:
  15. * log entries tat go to the log and trace file
  16. * error entries that go to the log and trace files
  17. * trace entries that go to the trace file only
  18. * trace entries can have a priority that allows us to filter lower priorities
  19. * trace entries also can be filtered by component if components are set
  20. */
  21. typedef enum
  22. {
  23. HT_MODE_TIME = 0x00000001, /* Add timestamp at beggining of line */
  24. HT_MODE_MTIME = 0x00000002, /* Use microseonds for tracing */
  25. HT_MODE_HEADER = 0x00000004, /* Add header to the begginign of line */
  26. HT_MODE_INDENT = 0x00000008, /* Indent on Function Enter */
  27. HT_MODE_MICRO = 0x00000010, /* Typical install */
  28. HT_MODE_COMPONENT = 0x00000020, /* Use components to trace */
  29. HT_MODE_TRACEPID = 0x00000040,
  30. HT_MODE_STDOUT_DUP = 0x00000080, /* Writes the log file to STDOUT */
  31. HT_MODE_ALL_VALID = 0x000000FF
  32. } HT_MODE;
  33. typedef enum
  34. {
  35. HT_DEBUG0 = 0x00,
  36. HT_DEBUG1 = 0x01,
  37. HT_DEBUG2 = 0x02,
  38. HT_DEBUG3 = 0x03,
  39. HT_DEBUG4 = 0x04,
  40. HT_DEBUG5 = 0x05,
  41. HT_DEBUG6 = 0x06,
  42. HT_DEBUG7 = 0x07,
  43. HT_DEBUG8 = 0x08,
  44. HT_DEBUG9 = 0x09
  45. } HT_DLEVEL;
  46. typedef enum
  47. {
  48. HT_E_NOERROR = 0,
  49. HT_E_BAD_MAGIC = 10000,
  50. HT_E_CANT_OPEN,
  51. HT_E_NOMEM,
  52. HT_E_BAD_PARAMS,
  53. HT_E_BAD_FLAGS,
  54. HT_E_ALREADY_INIT,
  55. HT_E_NOT_INIT
  56. } HT_E_CODE;
  57. typedef enum
  58. {
  59. HT_FD_LOG = 1,
  60. HT_FD_DBG = 2
  61. } HT_LOG_TYPE;
  62. /* To avoid write __LINE__, __FILE__ all the time, then define the following */
  63. #define HT_SEV_01 HT_DEBUG1,__FILE__,__LINE__
  64. #define HT_SEV_02 HT_DEBUG2,__FILE__,__LINE__
  65. #define HT_SEV_03 HT_DEBUG3,__FILE__,__LINE__
  66. #define HT_SEV_04 HT_DEBUG4,__FILE__,__LINE__
  67. #define HT_SEV_05 HT_DEBUG5,__FILE__,__LINE__
  68. #define HT_SEV_06 HT_DEBUG6,__FILE__,__LINE__
  69. #define HT_SEV_07 HT_DEBUG7,__FILE__,__LINE__
  70. #define HT_SEV_08 HT_DEBUG8,__FILE__,__LINE__
  71. #define HT_SEV_09 HT_DEBUG9,__FILE__,__LINE__
  72. #define TRACE_PATHSIZE 256
  73. #define TRACE_MAX_DATE_LEN 27 /* maximum lengths */
  74. #define TRACE_NOMS_DATE 20 /* date without microseconds */
  75. #define TRACE_MAX_MSG_LEN 10240
  76. #define TRACE_MAX_MSG_NUMBER 9 /* max number of formats in
  77. * message */
  78. #define TRACE_BAD_FD -1 /* opening trace file failed */
  79. #ifdef NT
  80. typedef mlong fhandle;
  81. #else
  82. typedef mint fhandle;
  83. #endif /* NT */
  84. typedef int4 severity;
  85. typedef struct
  86. {
  87. uint4 ht_flags; /* tracing flags */
  88. char ht_lfn[TRACE_PATHSIZE + 1]; /* log file name */
  89. fhandle ht_lfd; /* log file descriptor */
  90. char ht_dfn[TRACE_PATHSIZE + 1]; /* debug file name */
  91. fhandle ht_dfd; /* debug file descriptor */
  92. HT_DLEVEL ht_sev; /* debug trace level */
  93. char ht_header[256]; /* header for each line */
  94. char is_locked; /* is file locked? */
  95. } trace_file;
  96. #if defined(NT)
  97. #if !defined(EXPORT)
  98. #ifdef DLL
  99. #define EXPORT __declspec(dllexport)
  100. #else /* DLL */
  101. #define EXPORT __declspec(dllimport)
  102. #endif /* DLL */
  103. #endif /* EXPORT */
  104. #if !defined(STDCALL)
  105. #define STDCALL __stdcall
  106. #endif
  107. #else /* NT */
  108. #if !defined(EXPORT)
  109. #define EXPORT extern
  110. #endif
  111. #if !defined(STDCALL)
  112. #define STDCALL
  113. #endif
  114. #endif /* NT */
  115. EXPORT void STDCALL
  116. htenter (int severity,
  117. char *file_name,
  118. int line_number,
  119. char *funcname
  120. );
  121. EXPORT int STDCALL
  122. htexit (int severity,
  123. char *file_name,
  124. int line_number,
  125. int rc
  126. );
  127. void
  128. htrace(
  129. int severity,
  130. char *file_name,
  131. int line_number,
  132. char *format,
  133. ...
  134. );
  135. void
  136. writelog(
  137. char *format,
  138. ...
  139. );
  140. EXPORT void STDCALL
  141. heavytrace (HT_LOG_TYPE dest,
  142. char *fname,
  143. int lnum,
  144. int is_variable,
  145. char *format,
  146. va_list var_args
  147. );
  148. HT_E_CODE
  149. ht_trace_start(
  150. char *log_fn, /* IN: log file name */
  151. char *dbg_fn, /* IN: debug file name */
  152. HT_DLEVEL severity, /* IN: severity threshold for debug */
  153. int flags, /* IN: Flags for tracing */
  154. char *header_str /* IN: string to add to all messages */
  155. );