-
Notifications
You must be signed in to change notification settings - Fork 0
/
memfault_platform_log_config.h
48 lines (41 loc) · 1.99 KB
/
memfault_platform_log_config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! @file
//!
//! Copyright (c) Memfault, Inc.
//! See License.txt for details
//!
//! @brief
//! This provides the necessary implementation for connecting Memfault log
//! statements to the Nordic NRF5 SDK logging infrastructure. It's enabled by
//! setting '#define MEMFAULT_PLATFORM_HAS_LOG_CONFIG 1' in
//! memfault_platform_config.h.
#pragma once
#include "memfault/core/compiler.h"
#include "sdk_config.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_delay.h"
//! Note: NRF_LOG_FLUSH() needs to be called if NRF_LOG_DEFERRED=1 in order
//! for string formatters to print
#define _MEMFAULT_PORT_LOG_IMPL(_level, mflt_level, fmt, ...) \
do { \
MEMFAULT_SDK_LOG_SAVE(mflt_level, fmt, ## __VA_ARGS__); \
NRF_LOG_##_level("MFLT: " fmt, ## __VA_ARGS__); \
NRF_LOG_FLUSH(); \
} while (0)
#define MEMFAULT_LOG_DEBUG(fmt, ...) \
_MEMFAULT_PORT_LOG_IMPL(DEBUG, kMemfaultPlatformLogLevel_Debug, fmt, ## __VA_ARGS__)
#define MEMFAULT_LOG_INFO(fmt, ...) \
_MEMFAULT_PORT_LOG_IMPL(INFO, kMemfaultPlatformLogLevel_Info, fmt, ## __VA_ARGS__)
#define MEMFAULT_LOG_WARN(fmt, ...) \
_MEMFAULT_PORT_LOG_IMPL(WARNING, kMemfaultPlatformLogLevel_Warning, fmt, ## __VA_ARGS__)
#define MEMFAULT_LOG_ERROR(fmt, ...) \
_MEMFAULT_PORT_LOG_IMPL(ERROR, kMemfaultPlatformLogLevel_Error, fmt, ## __VA_ARGS__)
//! Note: nrf_delay_ms() is called to give the host a chance to drain the buffers and avoid Segger
//! RTT overruns (data will be dropped on the floor otherwise). NRF_LOG_FLUSH() is a no-op for the
//! RTT logging backend unfortunately.
#define MEMFAULT_LOG_RAW(fmt, ...) \
do { \
NRF_LOG_INTERNAL_RAW_INFO(fmt "\n", ## __VA_ARGS__); \
NRF_LOG_FLUSH(); \
nrf_delay_ms(1); \
} while (0)