lightduer_ds_log.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * Copyright (2017) Baidu Inc. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * Auth: Leliang Zhang(zhangleliang@baidu.com)
  18. * Desc: device log report
  19. */
  20. #ifndef BAIDU_DUER_LIGHTDUER_DS_LOG_H
  21. #define BAIDU_DUER_LIGHTDUER_DS_LOG_H
  22. #include "baidu_json.h"
  23. #include "lightduer_types.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. typedef enum _duer_ds_log_version_enum {
  28. DUER_DS_LOG_VERSION_UNKNOWN = 0x00,
  29. DUER_DS_LOG_VERSION_1_0 = 0x01,
  30. DUER_DS_LOG_VERSION_MAX = 0x08
  31. } duer_ds_log_version_enum_t;
  32. typedef enum _duer_ds_log_level_enum {
  33. DUER_DS_LOG_LEVEL_FATAL = 0x01,
  34. DUER_DS_LOG_LEVEL_ERROR = 0x02,
  35. DUER_DS_LOG_LEVEL_WARN = 0x03,
  36. DUER_DS_LOG_LEVEL_INFO = 0x04,
  37. DUER_DS_LOG_LEVEL_DEBUG = 0x05,
  38. DUER_DS_LOG_LEVEL_MAX = 0x08
  39. } duer_ds_log_level_enum_t;
  40. #ifndef DUER_DS_LOG_DEFAULT_REPORT_LEVEL
  41. #define DUER_DS_LOG_DEFAULT_REPORT_LEVEL DUER_DS_LOG_LEVEL_INFO
  42. #endif
  43. #ifndef DUER_DS_LOG_DEFAULT_CACHE_LEVEL
  44. #define DUER_DS_LOG_DEFAULT_CACHE_LEVEL DUER_DS_LOG_DEFAULT_REPORT_LEVEL
  45. #endif
  46. /*
  47. * update the report level,
  48. * DUER_DS_LOG_LEVEL_FATAL <= log_level <= DUER_DS_LOG_LEVEL_DEBUG
  49. * if < DUER_DS_LOG_LEVEL_FATAL, set to DUER_DS_LOG_LEVEL_FATAL
  50. * if > DUER_DS_LOG_LEVEL_DEBUG, set to DUER_DS_LOG_LEVEL_DEBUG
  51. * @param log_level
  52. * @return DUER_OK on success, other fail
  53. *
  54. */
  55. duer_status_t duer_ds_log_set_report_level(duer_ds_log_level_enum_t log_level);
  56. /**
  57. * init the control point for setting report level
  58. */
  59. void duer_ds_log_init(void);
  60. typedef enum _duer_ds_log_module_enum {
  61. DUER_DS_LOG_MODULE_CA = 0x01,
  62. DUER_DS_LOG_MODULE_RECORDER = 0x02,
  63. DUER_DS_LOG_MODULE_MEDIA = 0x03,
  64. DUER_DS_LOG_MODULE_HTTP = 0x04,
  65. DUER_DS_LOG_MODULE_DCS = 0x05,
  66. DUER_DS_LOG_MODULE_SPEEX = 0x06,
  67. DUER_DS_LOG_MODULE_OTA = 0x07,
  68. DUER_DS_LOG_MODULE_SYSTEM = 0x08,
  69. DUER_DS_LOG_MODULE_ANALYSIS = 0x09,
  70. DUER_DS_LOG_MODULE_BIND = 0x0A,
  71. DUER_DS_LOG_MODULE_MAX = 0x20
  72. } duer_ds_log_module_enum_t;
  73. typedef enum _duer_ds_log_family_enum {
  74. DUER_DS_LOG_FAMILY_UNKNOWN = 0x00,
  75. DUER_DS_LOG_FAMILY_MEMORY = 0x01,
  76. DUER_DS_LOG_FAMILY_NETWORK = 0x02,
  77. DUER_DS_LOG_FAMILY_MAX = 0x0F
  78. } duer_ds_log_family_enum_t;
  79. /**
  80. * {
  81. * "duer_trace_info": {
  82. * "code": [打点信息],
  83. * "message": [详细信息], // 可选
  84. * "ts": [当前时间戳]
  85. * }
  86. * }
  87. * the code format:
  88. * 0 1 2 3
  89. * 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
  90. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  91. * |X| Ver |X| Lel |X X X| Module | Family| Code |
  92. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  93. *
  94. */
  95. #define MASK_VERSION 0x70000000
  96. #define BITS_VERSION 0x07
  97. #define OFFSET_VERSION 28
  98. #define MASK_LEVEL 0x07000000
  99. #define BITS_LEVEL 0x07
  100. #define OFFSET_LEVEL 24
  101. #define MASK_MODULE 0x001F0000
  102. #define BITS_MODULE 0x1F
  103. #define OFFSET_MODULE 16
  104. #define MASK_FAMILY 0x0000F000
  105. #define BITS_FAMILY 0x0F
  106. #define OFFSET_FAMILY 12
  107. #define MASK_CODE 0x00000FFF
  108. #define BITS_CODE 0x0FFF
  109. #define OFFSET_CODE 0
  110. /**
  111. * generate the code in the above format from the input parameter
  112. * @param log_version
  113. * @param log_level
  114. * @param log_module
  115. * @param log_family
  116. * @param log_code
  117. * @return return the code in the above format
  118. */
  119. duer_u32_t duer_ds_log_generate_code(duer_ds_log_version_enum_t log_version,
  120. duer_ds_log_level_enum_t log_level,
  121. duer_ds_log_module_enum_t log_module,
  122. duer_ds_log_family_enum_t log_family,
  123. int log_code);
  124. /**
  125. * @param log_code the code in the above format which is 32bits
  126. * @return the version
  127. */
  128. duer_u32_t duer_ds_log_get_log_version(duer_u32_t log_code);
  129. /**
  130. * @param log_code the code in the above format which is 32bits
  131. * @return the level
  132. */
  133. duer_u32_t duer_ds_log_get_log_level(duer_u32_t log_code);
  134. /**
  135. * @param log_code the code in the above format which is 32bits
  136. * @return the module
  137. */
  138. duer_u32_t duer_ds_log_get_log_module(duer_u32_t log_code);
  139. /**
  140. * @param log_code the code in the above format which is 32bits
  141. * @return the family
  142. */
  143. duer_u32_t duer_ds_log_get_log_family(duer_u32_t log_code);
  144. /**
  145. * @param log_code the code in the above format which is 32bits
  146. * @return the code
  147. */
  148. duer_u32_t duer_ds_log_get_log_code(duer_u32_t log_code);
  149. /**
  150. * #param log_version the version of the log
  151. * @param log_level the log level, Fatal, Error, Warn, Info, Debug
  152. * @param log_module the module code
  153. * @param log_family the family of this log
  154. * @param log_code the code for this info, maybe use to parse the content of message
  155. * only the low 12bits use
  156. * @param log_message the content of the info, in json format
  157. * the caller should not try to release this if exist.
  158. * @return DUER_OK on success, or fail
  159. * an example:
  160. * {
  161. * "duer_trace_info": {
  162. * "code": 2001, //
  163. * "message": {
  164. * "reason": "REBOOT",
  165. * "count": 1
  166. * },
  167. * "ts": 220509360
  168. * }
  169. * }
  170. */
  171. duer_status_t duer_ds_log_v_f(duer_ds_log_version_enum_t log_version,
  172. duer_ds_log_level_enum_t log_level,
  173. duer_ds_log_module_enum_t log_module,
  174. duer_ds_log_family_enum_t log_family,
  175. int log_code,
  176. const baidu_json *log_message);
  177. duer_status_t duer_ds_log_f(duer_ds_log_level_enum_t log_level,
  178. duer_ds_log_module_enum_t log_module,
  179. duer_ds_log_family_enum_t log_family,
  180. int log_code,
  181. const baidu_json *log_message);
  182. duer_status_t duer_ds_log(duer_ds_log_level_enum_t log_level,
  183. duer_ds_log_module_enum_t log_module,
  184. int log_code,
  185. const baidu_json *log_message);
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif // BAIDU_DUER_LIGHTDUER_DS_LOG_H