Skip to content
Permalink
Browse files

logging: add frontend calls in log_core

Call frontend instead of processing if CONFIG_LOG_FRONTEND is enabled.

Signed-off-by: Marcin Szymczyk <Marcin.Szymczyk@nordicsemi.no>
  • Loading branch information...
masz-nordic authored and carlescufi committed Jun 13, 2019
1 parent 96ac04c commit a0c09961704d6b5dceada9e830542c1ba5a2fb34
Showing with 81 additions and 37 deletions.
  1. +10 −0 subsys/logging/Kconfig
  2. +71 −37 subsys/logging/log_core.c
@@ -14,6 +14,7 @@ if LOG

config LOG_RUNTIME_FILTERING
bool "Enable runtime reconfiguration of the logger"
depends on !LOG_FRONTEND
help
Allow runtime configuration of maximal, independent severity
level for instance.
@@ -68,6 +69,7 @@ config LOG_MAX_LEVEL
- 4 DEBUG, maximal level set to LOG_LEVEL_DBG

menu "Prepend log message with function name"
depends on !LOG_FRONTEND

config LOG_FUNC_NAME_PREFIX_ERR
bool "Error messages prepended"
@@ -223,6 +225,14 @@ config LOG_CMDS
depends on SHELL
default y if SHELL

config LOG_FRONTEND
bool "Enable frontend"
default n
select LOG_IMMEDIATE
help
When enabled, logs are redirected to a custom frontend instead
of being processed by the logger.

config LOG_BACKEND_UART
bool "Enable UART backend"
depends on UART_CONSOLE
@@ -14,6 +14,7 @@
#include <assert.h>
#include <sys/atomic.h>
#include <ctype.h>
#include <logging/log_frontend.h>

LOG_MODULE_REGISTER(log);

@@ -217,38 +218,50 @@ static inline void msg_finalize(struct log_msg *msg,

void log_0(const char *str, struct log_msg_ids src_level)
{
struct log_msg *msg = log_msg_create_0(str);
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_0(str, src_level);
} else {
struct log_msg *msg = log_msg_create_0(str);

if (msg == NULL) {
return;
if (msg == NULL) {
return;
}
msg_finalize(msg, src_level);
}
msg_finalize(msg, src_level);
}

void log_1(const char *str,
log_arg_t arg0,
struct log_msg_ids src_level)
{
struct log_msg *msg = log_msg_create_1(str, arg0);
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_1(str, arg0, src_level);
} else {
struct log_msg *msg = log_msg_create_1(str, arg0);

if (msg == NULL) {
return;
if (msg == NULL) {
return;
}
msg_finalize(msg, src_level);
}
msg_finalize(msg, src_level);
}

void log_2(const char *str,
log_arg_t arg0,
log_arg_t arg1,
struct log_msg_ids src_level)
{
struct log_msg *msg = log_msg_create_2(str, arg0, arg1);
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_2(str, arg0, arg1, src_level);
} else {
struct log_msg *msg = log_msg_create_2(str, arg0, arg1);

if (msg == NULL) {
return;
}
if (msg == NULL) {
return;
}

msg_finalize(msg, src_level);
msg_finalize(msg, src_level);
}
}

void log_3(const char *str,
@@ -257,41 +270,53 @@ void log_3(const char *str,
log_arg_t arg2,
struct log_msg_ids src_level)
{
struct log_msg *msg = log_msg_create_3(str, arg0, arg1, arg2);
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_3(str, arg0, arg1, arg2, src_level);
} else {
struct log_msg *msg = log_msg_create_3(str, arg0, arg1, arg2);

if (msg == NULL) {
return;
}
if (msg == NULL) {
return;
}

msg_finalize(msg, src_level);
msg_finalize(msg, src_level);
}
}

void log_n(const char *str,
log_arg_t *args,
u32_t narg,
struct log_msg_ids src_level)
{
struct log_msg *msg = log_msg_create_n(str, args, narg);
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_n(str, args, narg, src_level);
} else {
struct log_msg *msg = log_msg_create_n(str, args, narg);

if (msg == NULL) {
return;
}
if (msg == NULL) {
return;
}

msg_finalize(msg, src_level);
msg_finalize(msg, src_level);
}
}

void log_hexdump(const char *str,
const u8_t *data,
u32_t length,
struct log_msg_ids src_level)
{
struct log_msg *msg = log_msg_hexdump_create(str, data, length);
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_hexdump(str, data, length, src_level);
} else {
struct log_msg *msg = log_msg_hexdump_create(str, data, length);

if (msg == NULL) {
return;
}
if (msg == NULL) {
return;
}

msg_finalize(msg, src_level);
msg_finalize(msg, src_level);
}
}

int log_printk(const char *fmt, va_list ap)
@@ -350,7 +375,8 @@ static u32_t count_args(const char *fmt)

void log_generic(struct log_msg_ids src_level, const char *fmt, va_list ap)
{
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE)) {
if (IS_ENABLED(CONFIG_LOG_IMMEDIATE) &&
(!IS_ENABLED(CONFIG_LOG_FRONTEND))) {
struct log_backend const *backend;
u32_t timestamp = timestamp_func();

@@ -388,16 +414,20 @@ void log_string_sync(struct log_msg_ids src_level, const char *fmt, ...)
void log_hexdump_sync(struct log_msg_ids src_level, const char *metadata,
const u8_t *data, u32_t len)
{
struct log_backend const *backend;
u32_t timestamp = timestamp_func();
if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_hexdump(metadata, data, len, src_level);
} else {
struct log_backend const *backend;
u32_t timestamp = timestamp_func();

for (int i = 0; i < log_backend_count_get(); i++) {
backend = log_backend_get(i);
for (int i = 0; i < log_backend_count_get(); i++) {
backend = log_backend_get(i);

if (log_backend_is_active(backend)) {
log_backend_put_sync_hexdump(backend, src_level,
timestamp, metadata,
data, len);
if (log_backend_is_active(backend)) {
log_backend_put_sync_hexdump(backend, src_level,
timestamp, metadata,
data, len);
}
}
}
}
@@ -455,6 +485,10 @@ void log_init(void)
assert(log_backend_count_get() < LOG_FILTERS_NUM_OF_SLOTS);
int i;

if (IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_frontend_init();
}

if (atomic_inc(&initialized) != 0) {
return;
}

0 comments on commit a0c0996

Please sign in to comment.
You can’t perform that action at this time.