Skip to content

Commit 01b3724

Browse files
authored
sinks: android: handle when message is not loggable (gabime#2801)
Android logger (since API 30) checks the per-tag property `log.tag.<tag>` to determine if a log message is loggable. See https://developer.android.com/ndk/reference/group/logging#__android_log_is_loggable . For example, `__android_log_buf_write` for a VERBOSE message will call `__android_log_is_loggable` and return `-EPERM` if the log message will not be printed because `log.tag.<tag>` is set to `INFO`. Instead of erroring with the following error message, the Android sink should handle `-EPERM`. It is not an error to disable a log via the run-time property. ``` [*** LOG ERROR #1 ***] [2023-06-29 00:50:26] [logcat] logging to Android failed: Unknown error -1 [/path/to/file.cpp(123)] ```
1 parent 4b8ff51 commit 01b3724

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

include/spdlog/sinks/android_sink.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class android_sink final : public base_sink<Mutex>
5656

5757
// See system/core/liblog/logger_write.c for explanation of return value
5858
int ret = android_log(priority, tag_.c_str(), msg_output);
59+
if (ret == -EPERM)
60+
{
61+
return; // !__android_log_is_loggable
62+
}
5963
int retry_count = 0;
6064
while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
6165
{

0 commit comments

Comments
 (0)