logging: Add LOG_RAW macro
Add macro for logging raw formatted string. It is similar to LOG_PRINTK macro but contrary to LOG_PRINTK it should not append carriage return character to any new line character found in the string. LOG_PRINTK processed by log_output module has that to mimic printk behavior. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
c7d37d956e
commit
dbda37ddf0
4 changed files with 36 additions and 5 deletions
|
@ -79,7 +79,17 @@ extern "C" {
|
||||||
* @param ... A string optionally containing printk valid conversion specifier,
|
* @param ... A string optionally containing printk valid conversion specifier,
|
||||||
* followed by as many values as specifiers.
|
* followed by as many values as specifiers.
|
||||||
*/
|
*/
|
||||||
#define LOG_PRINTK(...) Z_LOG_PRINTK(__VA_ARGS__)
|
#define LOG_PRINTK(...) Z_LOG_PRINTK(0, __VA_ARGS__)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Unconditionally print raw log message.
|
||||||
|
*
|
||||||
|
* Provided string is printed as is without appending any characters (e.g., color or newline).
|
||||||
|
*
|
||||||
|
* @param ... A string optionally containing printk valid conversion specifier,
|
||||||
|
* followed by as many values as specifiers.
|
||||||
|
*/
|
||||||
|
#define LOG_RAW(...) Z_LOG_PRINTK(1, __VA_ARGS__)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Writes an ERROR level message associated with the instance to the log.
|
* @brief Writes an ERROR level message associated with the instance to the log.
|
||||||
|
|
|
@ -391,7 +391,17 @@ static inline char z_log_minimal_level_to_char(int level)
|
||||||
extern struct log_source_const_data __log_const_start[];
|
extern struct log_source_const_data __log_const_start[];
|
||||||
extern struct log_source_const_data __log_const_end[];
|
extern struct log_source_const_data __log_const_end[];
|
||||||
|
|
||||||
#define Z_LOG_PRINTK(...) do { \
|
/** @brief Create message for logging printk-like string or a raw string.
|
||||||
|
*
|
||||||
|
* Part of printk string processing is appending of carriage return after any
|
||||||
|
* new line character found in the string. If it is not desirable then @p _is_raw
|
||||||
|
* can be set to 1 to indicate raw string. This information is stored in the source
|
||||||
|
* field which is not used for its typical purpose in this case.
|
||||||
|
*
|
||||||
|
* @param _is_raw Set to 1 to indicate raw string, set to 0 to indicate printk.
|
||||||
|
* @param ... Format string with arguments.
|
||||||
|
*/
|
||||||
|
#define Z_LOG_PRINTK(_is_raw, ...) do { \
|
||||||
if (IS_ENABLED(CONFIG_LOG_MODE_MINIMAL)) { \
|
if (IS_ENABLED(CONFIG_LOG_MODE_MINIMAL)) { \
|
||||||
z_log_minimal_printk(__VA_ARGS__); \
|
z_log_minimal_printk(__VA_ARGS__); \
|
||||||
break; \
|
break; \
|
||||||
|
@ -401,7 +411,7 @@ extern struct log_source_const_data __log_const_end[];
|
||||||
z_log_printf_arg_checker(__VA_ARGS__); \
|
z_log_printf_arg_checker(__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), _mode, \
|
Z_LOG_MSG2_CREATE(!IS_ENABLED(CONFIG_USERSPACE), _mode, \
|
||||||
CONFIG_LOG_DOMAIN_ID, NULL, \
|
CONFIG_LOG_DOMAIN_ID, (uintptr_t)_is_raw, \
|
||||||
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
|
LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
|
@ -412,6 +412,11 @@ static bool msg_filter_check(struct log_backend const *backend,
|
||||||
domain_id = log_msg_get_domain(&msg->log);
|
domain_id = log_msg_get_domain(&msg->log);
|
||||||
source_id = source ? log_dynamic_source_id(source) : -1;
|
source_id = source ? log_dynamic_source_id(source) : -1;
|
||||||
|
|
||||||
|
/* Accept all non-logging messages. */
|
||||||
|
if (level == LOG_LEVEL_NONE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
backend_level = log_filter_get(backend, domain_id,
|
backend_level = log_filter_get(backend, domain_id,
|
||||||
source_id, true);
|
source_id, true);
|
||||||
|
|
||||||
|
|
|
@ -491,16 +491,22 @@ void log_output_process(const struct log_output *output,
|
||||||
{
|
{
|
||||||
bool raw_string = (level == LOG_LEVEL_INTERNAL_RAW_STRING);
|
bool raw_string = (level == LOG_LEVEL_INTERNAL_RAW_STRING);
|
||||||
uint32_t prefix_offset;
|
uint32_t prefix_offset;
|
||||||
|
cbprintf_cb cb;
|
||||||
|
|
||||||
if (!raw_string) {
|
if (!raw_string) {
|
||||||
prefix_offset = prefix_print(output, flags, 0, timestamp, domain, source, level);
|
prefix_offset = prefix_print(output, flags, 0, timestamp, domain, source, level);
|
||||||
|
cb = out_func;
|
||||||
} else {
|
} else {
|
||||||
prefix_offset = 0;
|
prefix_offset = 0;
|
||||||
|
/* source set to 1 indicates raw string and contrary to printk
|
||||||
|
* case it should not append anything to the output (printk is
|
||||||
|
* appending <CR> to the new line character).
|
||||||
|
*/
|
||||||
|
cb = ((uintptr_t)source == 1) ? out_func : cr_out_func;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (package) {
|
if (package) {
|
||||||
int err = cbpprintf(raw_string ? cr_out_func : out_func,
|
int err = cbpprintf(cb, (void *)output, (void *)package);
|
||||||
(void *)output, (void *)package);
|
|
||||||
|
|
||||||
(void)err;
|
(void)err;
|
||||||
__ASSERT_NO_MSG(err >= 0);
|
__ASSERT_NO_MSG(err >= 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue