Skip to content

Commit 7fab5ab

Browse files
author
Arto Kinnunen
committed
Squashed 'features/frameworks/mbed-trace/' changes from 6df2572..9eaf0d1
9eaf0d1 Add documentation on how to change trace level. (#85) git-subtree-dir: features/frameworks/mbed-trace git-subtree-split: 9eaf0d146f0804a700aafbbd896f02c1acaaae66
1 parent 7a58eae commit 7fab5ab

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,43 @@ Set the output function, `printf` by default:
109109
mbed_trace_print_function_set(printf)
110110
```
111111
112+
### Tracing level
113+
114+
Run time tracing level is set using `mbed_trace_set_config()` function. Possible levels and examples how to set them is presented below.
115+
116+
```c
117+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
118+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); // (same as ALL)
119+
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO);
120+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN);
121+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR);
122+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_CMD);
123+
//mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE);
124+
```
125+
126+
Build time optimization can be done with `MBED_TRACE_MAX_LEVEL` definition. Setting max level to `TRACE_LEVEL_DEBUG` includes all traces to the build. Setting max level to `TRACE_LEVEL_INFO` includes all but `tr_debug()` traces to the build. Other maximum tracing levels follow the same behavior and no messages above the selected level are included in the build.
127+
128+
```c
129+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
130+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_INFO
131+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_WARN
132+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_ERROR
133+
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_CMD
134+
```
135+
136+
In Mbed OS, the build time maximum tracing level can be set through `mbed_app.json` as shown below.
137+
138+
```
139+
{
140+
"target_overrides":{
141+
"*":{
142+
"mbed-trace.enable": true,
143+
"mbed-trace.max-level": "TRACE_LEVEL_INFO"
144+
}
145+
}
146+
}
147+
```
148+
112149
### Helping functions
113150

114151
The purpose of the helping functions is to provide simple conversions, for example from an array to C string, so that you can print everything to single trace line. They must be called inside the actual trace calls, for example:

mbed_lib.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"help": "Used to globally enable traces.",
66
"value": null
77
},
8+
"max-level": {
9+
"help": "This flag is used to optimize the code size. For example, setting trace optimization level to TRACE_LEVEL_INFO will define all tr_debug() macros empty, which reduces the binary size. The possible optimization levels are TRACE_LEVEL_DEBUG, TRACE_LEVEL_INFO, TRACE_LEVEL_WARN, TRACE_LEVEL_ERROR and TRACE_LEVEL_CMD. To set the output tracing level, please use mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO). The possible tracing levels for mbed_trace_config_set() are TRACE_ACTIVE_LEVEL_ALL, TRACE_ACTIVE_LEVEL_DEBUG (same as ALL), TRACE_ACTIVE_LEVEL_INFO, TRACE_ACTIVE_LEVEL_WARN, TRACE_ACTIVE_LEVEL_ERROR, TRACE_ACTIVE_LEVEL_CMD and TRACE_LEVEL_NONE.",
10+
"value": null,
11+
"macro_name": "MBED_TRACE_MAX_LEVEL"
12+
13+
},
814
"fea-ipv6": {
915
"help": "Used to globally disable ipv6 tracing features.",
1016
"value": null

test/Test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ TEST(trace, config_change)
239239
TEST(trace, active_level_all_color)
240240
{
241241
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
242+
// unknown debug level
243+
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
244+
STRCMP_EQUAL(" hep", buf);
242245
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
243246
STRCMP_EQUAL("\x1b[90m[DBG ][mygr]: hello\x1b[0m", buf);
244247
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "to one");
@@ -268,6 +271,10 @@ TEST(trace, change_levels)
268271
TEST(trace, active_level_debug)
269272
{
270273
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
274+
275+
// unknown debug level
276+
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
277+
STRCMP_EQUAL(" hep", buf);
271278

272279
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
273280
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);

0 commit comments

Comments
 (0)