Commit 5f6070e2 authored by Krzysztof Chruściński's avatar Krzysztof Chruściński Committed by Jukka Rissanen
Browse files

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: default avatarKrzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
parent 51844448
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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
+8 −4
Original line number Diff line number Diff line
@@ -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];
@@ -59,8 +60,10 @@ extern const struct log_backend __log_backends_end[0];
 *
 * @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					       \
	}


+1 −1
Original line number Diff line number Diff line
@@ -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);					     \
+3 −1
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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);
Loading