Skip to content

Commit

Permalink
Temporarily lower log level in mgos_debug_write()
Browse files Browse the repository at this point in the history
To inhibit logging while logging.
  • Loading branch information
rojer committed Jan 24, 2020
1 parent 868ea09 commit 0d552e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/mgos_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C" {
struct mgos_debug_hook_arg {
int fd;
enum cs_log_level level;
const void *data;
const char *data;
size_t len;

/*
Expand Down
10 changes: 8 additions & 2 deletions src/mgos_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ extern enum cs_log_level cs_log_cur_msg_level;

void mgos_debug_write(int fd, const void *data, size_t len) {
char buf[MGOS_DEBUG_TMP_BUF_SIZE];
enum cs_log_level old_level;
int uart_no = -1;
debug_lock();
if (s_in_debug) {
debug_unlock();
return;
}
s_in_debug = true;
old_level = cs_log_level;
cs_log_level = LL_NONE;
if (s_uart_suspended <= 0) {
if (fd == 1) {
uart_no = s_stdout_uart;
Expand All @@ -72,7 +75,7 @@ void mgos_debug_write(int fd, const void *data, size_t len) {
}
}
if (uart_no >= 0) {
len = mgos_uart_write(uart_no, data, len);
mgos_uart_write(uart_no, data, len);
mgos_uart_flush(uart_no);
}
if (!mgos_sys_config_is_initialized()) {
Expand All @@ -97,20 +100,23 @@ void mgos_debug_write(int fd, const void *data, size_t len) {
/* Invoke all registered debug_write hooks */
/* Only send LL_INFO messages and below, to avoid loops. */
#if CS_ENABLE_STDIO
if (cs_log_cur_msg_level <= LL_INFO)
if (cs_log_cur_msg_level <= mgos_sys_config_get_debug_event_level())
#endif
{
struct mgos_debug_hook_arg arg = {
.buf = buf,
.fd = fd,
#if CS_ENABLE_STDIO
.level = cs_log_cur_msg_level,
#endif
.data = data,
.len = len,
};
mgos_event_trigger(MGOS_EVENT_LOG, &arg);
}

out_unlock:
cs_log_level = old_level;
s_in_debug = false;
debug_unlock();
}
Expand Down

0 comments on commit 0d552e3

Please sign in to comment.