Commit 0705151
Marcin Radomski
Use __android_log_is_loggable in AndroidLogger::enabled
Android's C logging API determines the effective log level based on a
combination [1] of a global variable, system-wide properties [2], and
call-specific default. log + android_logger crates add another layer of
log filtering on top of that, independent from the C API.
```
.-----.
| app |
'-----'
|
v
.-----------. filter by STATIC_MAX_LEVEL [3] +
| log crate | - MAX_LOG_LEVEL_FILTER [4],
'-----------' overrideable via log::set_max_level
|
v
.----------------------.
| android_logger crate | - filter by Config::max_level [5]
'----------------------'
|
v
.--------.
| liblog | - filter by global state or system-wide properties [2]
'--------'
```
The result is that in mixed C/C++ + Rust applications, logs originating
from Rust use the least verbose level configured, which sometimes
results in unexpected loss of logs.
In addition, adjusting the log level globally via system properties,
very useful in work on the AOSP itself, currently works only up to the
level android_logger defaults to.
This change makes AndroidLogger completely delegate log filtering to the
underlying liblog when Config::max_level is unset by using
__android_log_is_loggable.
Setting Config::max_level, or calling log::set_max_level still keep the
existing behavior of filtering the logs before they reach liblog, but
the default is now to have the log level consistent between Rust and
C/C++ logs.
It also removes one TODO from the code :)
Tested by:
- running a test app that uses Rust logs of all levels on a rooted
device, using both Android's liblog C API and android_logger ones
- adjusting the log.tag system property [2] via adb shell setprop
- verifying the message filtering changes according to log.tag changes
consistently for logs from both languages
[1] https://cs.android.com/android/platform/superproject/main/+/main:system/logging/liblog/properties.cpp;l=243;drc=b74a506c1b69f5b295a8cdfd7e2da3b16db15934
[2] https://cs.android.com/android/platform/superproject/main/+/main:system/logging/logd/README.property;l=45;drc=99c545d3098018a544cb292e1501daca694bee0f
[3] https://github.com/rust-lang/log/blob/0551261bb4588b7f8afc8be05640347c97b67e10/src/lib.rs#L1536
[4] https://github.com/rust-lang/log/blob/0551261bb4588b7f8afc8be05640347c97b67e10/src/lib.rs#L469
[5] https://github.com/rust-mobile/android_logger-rs/blob/d51b7ffdacf20fb09fd36a6b309b50240ef50728/src/lib.rs#L1981 parent 151aefc commit 0705151
4 files changed
+74
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
31 | 84 | | |
32 | 85 | | |
33 | 86 | | |
| |||
61 | 114 | | |
62 | 115 | | |
63 | 116 | | |
64 | | - | |
65 | | - | |
66 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
67 | 124 | | |
68 | 125 | | |
69 | 126 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
152 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | 163 | | |
| |||
0 commit comments