nrf_log_ctrl.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. * Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF_LOG_CTRL_H
  41. #define NRF_LOG_CTRL_H
  42. /**@file
  43. * @addtogroup nrf_log Logger module
  44. * @ingroup app_common
  45. *
  46. * @defgroup nrf_log_ctrl Functions for controlling nrf_log
  47. * @{
  48. * @ingroup nrf_log
  49. * @brief The nrf_log control interface.
  50. */
  51. #include "sdk_config.h"
  52. #include "sdk_errors.h"
  53. #include <stdint.h>
  54. #include <stdbool.h>
  55. #include "nrf_log_types.h"
  56. #include "nrf_log_ctrl_internal.h"
  57. #include "nrf_log_backend_interface.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. /**
  62. * @brief Timestamp function prototype.
  63. *
  64. * @return Timestamp value.
  65. */
  66. typedef uint32_t (*nrf_log_timestamp_func_t)(void);
  67. /**@brief Macro for initializing the logs.
  68. *
  69. * Macro has one or two parameters. First parameter (obligatory) is the timestamp function (@ref nrf_log_timestamp_func_t).
  70. * Additionally, as the second parameter timestamp frequency in Hz can be provided. If not provided then default
  71. * frequency is used (@ref NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY). Frequency is used to format timestamp prefix if
  72. * @ref NRF_LOG_STR_FORMATTER_TIMESTAMP_FORMAT_ENABLED is set.
  73. *
  74. * @return NRF_SUCCESS after successful initialization, otherwise an error code.
  75. */
  76. #define NRF_LOG_INIT(...) NRF_LOG_INTERNAL_INIT(__VA_ARGS__)
  77. /**@brief Macro for processing a single log entry from a queue of deferred logs.
  78. *
  79. * You can call this macro from the main context or from the error handler to process
  80. * log entries one by one.
  81. *
  82. * @note If logs are not deferred, this call has no use and is defined as 'false'.
  83. *
  84. * @retval true There are more logs to process in the buffer.
  85. * @retval false No more logs in the buffer.
  86. */
  87. #define NRF_LOG_PROCESS() NRF_LOG_INTERNAL_PROCESS()
  88. /** @brief Macro for processing all log entries from the buffer.
  89. * It blocks until all buffered entries are processed by the backend.
  90. *
  91. * @note If logs are not deferred, this call has no use and is empty.
  92. */
  93. #define NRF_LOG_FLUSH() NRF_LOG_INTERNAL_FLUSH()
  94. /** @brief Macro for flushing log data before reset.
  95. *
  96. * @note If logs are not deferred, this call has no use and is empty.
  97. *
  98. * @note If RTT is used, then a breakpoint is hit once flushed.
  99. */
  100. #define NRF_LOG_FINAL_FLUSH() NRF_LOG_INTERNAL_FINAL_FLUSH()
  101. /**
  102. * @brief Function for initializing the frontend and the default backend.
  103. *
  104. * @ref NRF_LOG_INIT calls this function to initialize the frontend and the backend.
  105. * If custom backend is used, then @ref NRF_LOG_INIT should not be called.
  106. * Instead, frontend and user backend should be verbosely initialized.
  107. *
  108. * @param timestamp_func Function for getting a 32-bit timestamp.
  109. * @param timestamp_freq Frequency of the timestamp.
  110. *
  111. * @return Error status.
  112. *
  113. */
  114. ret_code_t nrf_log_init(nrf_log_timestamp_func_t timestamp_func, uint32_t timestamp_freq);
  115. /**
  116. * @brief Function for adding new backend interface to the logger.
  117. *
  118. * @param p_backend Pointer to the backend interface.
  119. * @param severity Initial value of severity level for each module forwarded to the backend. This
  120. * option is only applicable if @ref NRF_LOG_FILTERS_ENABLED is set.
  121. * @return -1 if backend cannot be added or positive number (backend ID).
  122. */
  123. int32_t nrf_log_backend_add(nrf_log_backend_t const * p_backend, nrf_log_severity_t severity);
  124. /**
  125. * @brief Function for removing backend from the logger.
  126. *
  127. * @param p_backend Pointer to the backend interface.
  128. *
  129. */
  130. void nrf_log_backend_remove(nrf_log_backend_t const * p_backend);
  131. /**
  132. * @brief Function for setting logger backends into panic mode.
  133. *
  134. * When this function is called all attached backends are informed about panic state of the system.
  135. * It is up to the backend to react properly (hold or process logs in blocking mode, etc.)
  136. */
  137. void nrf_log_panic(void);
  138. /**
  139. * @brief Function for handling a single log entry.
  140. *
  141. * Use this function only if the logs are buffered. It takes a single entry from the
  142. * buffer and attempts to process it.
  143. *
  144. * @retval true If there are more entries to process.
  145. * @retval false If there are no more entries to process.
  146. */
  147. bool nrf_log_frontend_dequeue(void);
  148. /**
  149. * @brief Function for getting number of independent log modules registered into the logger.
  150. *
  151. * @return Number of registered modules.
  152. */
  153. uint32_t nrf_log_module_cnt_get(void);
  154. /**
  155. * @brief Function for getting module name.
  156. *
  157. * @param module_id Module ID.
  158. * @param is_ordered_idx Module ID is given is index in alphabetically sorted list of modules.
  159. * @return Pointer to string with module name.
  160. */
  161. const char * nrf_log_module_name_get(uint32_t module_id, bool is_ordered_idx);
  162. /**
  163. * @brief Function for getting coloring of specific logs.
  164. *
  165. * @param module_id Module ID.
  166. * @param severity Log severity.
  167. *
  168. * @return ID of the color.
  169. */
  170. uint8_t nrf_log_color_id_get(uint32_t module_id, nrf_log_severity_t severity);
  171. /**
  172. * @brief Function for configuring filtering ofs logs in the module.
  173. *
  174. * Filtering of logs in modules is independent for each backend.
  175. *
  176. * @param backend_id Backend ID which want to chenge its configuration.
  177. * @param module_id Module ID which logs will be reconfigured.
  178. * @param severity New severity filter.
  179. */
  180. void nrf_log_module_filter_set(uint32_t backend_id,
  181. uint32_t module_id,
  182. nrf_log_severity_t severity);
  183. /**
  184. * @brief Function for getting module severity level.
  185. *
  186. * @param backend_id Backend ID.
  187. * @param module_id Module ID.
  188. * @param is_ordered_idx Module ID is given is index in alphabetically sorted list of modules.
  189. * @param dynamic It true current filter for given backend is returned. If false then
  190. * compiled-in level is returned (maximum available). If this parameter is
  191. * false then backend_id parameter is not used.
  192. *
  193. * @return Severity.
  194. */
  195. nrf_log_severity_t nrf_log_module_filter_get(uint32_t backend_id,
  196. uint32_t module_id,
  197. bool is_ordered_idx,
  198. bool dynamic);
  199. /**
  200. * @brief Function stores current filtering configuration into non-volatile memory using @ref fds module.
  201. *
  202. * @return NRF_SUCCESS or @ref fds error code.
  203. */
  204. ret_code_t nrf_log_config_store(void);
  205. /**
  206. * @brief Function loads configuration from non-volatile memory using @ref fds module.
  207. *
  208. * @retval NRF_SUCCESS On successful loading.
  209. * @retval NRF_ERROR_NOT_FOUND Configuration file not found.
  210. * @retval NRF_ERROR_INTERNAL Other @ref fds error on reading configuration file.
  211. */
  212. ret_code_t nrf_log_config_load(void);
  213. #ifdef __cplusplus
  214. }
  215. #endif
  216. #endif // NRF_LOG_CTRL_H
  217. /**
  218. *@}
  219. **/