logging: Add autostart option to LOG_BACKEND_DEFINE
Extended macro to accept flag indicating if given backend must be initialized and enabled when log subsystem starts. Typically, simple backends will have autostart flag set. More complex may require explicit enabling (e.g. shell over BLE can only be enabled when BLE connection is established). Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
518444487c
commit
5f6070e2f7
7 changed files with 24 additions and 16 deletions
|
@ -427,8 +427,8 @@ Example message formatted using :cpp:func:`log_output_msg_process`.
|
|||
}
|
||||
|
||||
Logger backends are registered to the logger using
|
||||
:c:macro:`LOG_BACKEND_DEFINE` macro. The macro creates an instance in the dedicated
|
||||
memory section. Backends can be dynamically enabled
|
||||
:c:macro:`LOG_BACKEND_DEFINE` macro. The macro creates an instance in the
|
||||
dedicated memory section. Backends can be dynamically enabled
|
||||
(:cpp:func:`log_backend_enable`) and disabled.
|
||||
|
||||
Limitations
|
||||
|
|
|
@ -49,6 +49,7 @@ struct log_backend {
|
|||
const struct log_backend_api *api;
|
||||
struct log_backend_control_block *cb;
|
||||
const char *name;
|
||||
bool autostart;
|
||||
};
|
||||
|
||||
extern const struct log_backend __log_backends_start[0];
|
||||
|
@ -57,10 +58,12 @@ extern const struct log_backend __log_backends_end[0];
|
|||
/**
|
||||
* @brief Macro for creating a logger backend instance.
|
||||
*
|
||||
* @param _name Name of the backend instance.
|
||||
* @param _api Logger backend API.
|
||||
* @param _name Name of the backend instance.
|
||||
* @param _api Logger backend API.
|
||||
* @param _autostart If true backend is initialized and activated together
|
||||
* with the logger subsystem.
|
||||
*/
|
||||
#define LOG_BACKEND_DEFINE(_name, _api) \
|
||||
#define LOG_BACKEND_DEFINE(_name, _api, _autostart) \
|
||||
static struct log_backend_control_block UTIL_CAT(backend_cb_, _name) = \
|
||||
{ \
|
||||
.active = false, \
|
||||
|
@ -71,7 +74,8 @@ extern const struct log_backend __log_backends_end[0];
|
|||
{ \
|
||||
.api = &_api, \
|
||||
.cb = &UTIL_CAT(backend_cb_, _name), \
|
||||
.name = STRINGIFY(_name) \
|
||||
.name = STRINGIFY(_name), \
|
||||
.autostart = _autostart \
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ int shell_log_backend_output_func(u8_t *data, size_t length, void *ctx);
|
|||
*/
|
||||
#if CONFIG_LOG
|
||||
#define SHELL_LOG_BACKEND_DEFINE(_name, _buf, _size) \
|
||||
LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api); \
|
||||
LOG_BACKEND_DEFINE(_name##_backend, log_backend_shell_api, false); \
|
||||
K_FIFO_DEFINE(_name##_fifo); \
|
||||
LOG_OUTPUT_DEFINE(_name##_log_output, shell_log_backend_output_func, \
|
||||
_buf, _size); \
|
||||
|
|
|
@ -89,4 +89,6 @@ const struct log_backend_api log_backend_native_posix_api = {
|
|||
.panic = panic,
|
||||
};
|
||||
|
||||
LOG_BACKEND_DEFINE(log_backend_native_posix, log_backend_native_posix_api);
|
||||
LOG_BACKEND_DEFINE(log_backend_native_posix,
|
||||
log_backend_native_posix_api,
|
||||
true);
|
||||
|
|
|
@ -68,4 +68,4 @@ const struct log_backend_api log_backend_uart_api = {
|
|||
.init = log_backend_uart_init,
|
||||
};
|
||||
|
||||
LOG_BACKEND_DEFINE(log_backend_uart, log_backend_uart_api);
|
||||
LOG_BACKEND_DEFINE(log_backend_uart, log_backend_uart_api, true);
|
||||
|
|
|
@ -271,12 +271,14 @@ void log_init(void)
|
|||
log_backend_id_set(backend,
|
||||
i + LOG_FILTER_FIRST_BACKEND_SLOT_IDX);
|
||||
|
||||
backend_filter_init(backend);
|
||||
if (backend->api->init) {
|
||||
backend->api->init();
|
||||
}
|
||||
if (backend->autostart) {
|
||||
backend_filter_init(backend);
|
||||
if (backend->api->init) {
|
||||
backend->api->init();
|
||||
}
|
||||
|
||||
log_backend_activate(backend, NULL);
|
||||
log_backend_activate(backend, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,10 +101,10 @@ const struct log_backend_api log_backend_test_api = {
|
|||
.panic = panic,
|
||||
};
|
||||
|
||||
LOG_BACKEND_DEFINE(backend1, log_backend_test_api);
|
||||
LOG_BACKEND_DEFINE(backend1, log_backend_test_api, true);
|
||||
struct backend_cb backend1_cb;
|
||||
|
||||
LOG_BACKEND_DEFINE(backend2, log_backend_test_api);
|
||||
LOG_BACKEND_DEFINE(backend2, log_backend_test_api, true);
|
||||
struct backend_cb backend2_cb;
|
||||
|
||||
static u32_t stamp;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue