Skip to content

Commit

Permalink
sinks: android: handle when message is not loggable (#2801)
Browse files Browse the repository at this point in the history
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)]
```
  • Loading branch information
lucasrangit committed Jul 6, 2023
1 parent 4b8ff51 commit 01b3724
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/spdlog/sinks/android_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class android_sink final : public base_sink<Mutex>

// See system/core/liblog/logger_write.c for explanation of return value
int ret = android_log(priority, tag_.c_str(), msg_output);
if (ret == -EPERM)
{
return; // !__android_log_is_loggable
}
int retry_count = 0;
while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES))
{
Expand Down

0 comments on commit 01b3724

Please sign in to comment.