From 1b63e068ae86c231231df17f98551a2d218694e8 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Sun, 2 Feb 2025 16:55:46 +0100 Subject: [PATCH] stumbled upon _NSSetLogCStringFunction to hide IOBluetoothDeviceInquiry debug messages --- CHANGELOG.md | 2 ++ blueutil.m | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93b290c..8938d9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## unreleased +* Hide debug log messages from IOBluetoothDeviceInquiry [@toy](https://github.com/toy) + ## v2.11.0 (2025-01-18) * Inform the user on receiving abort signal, that it may be due to absence of permission [#95](https://github.com/toy/blueutil/issues/95) [@toy](https://github.com/toy) diff --git a/blueutil.m b/blueutil.m index c249888..89adc96 100644 --- a/blueutil.m +++ b/blueutil.m @@ -49,6 +49,8 @@ int assert_reg(int errcode, const regex_t *restrict preg, char *reason) { int IOBluetoothPreferenceGetDiscoverableState(); void IOBluetoothPreferenceSetDiscoverableState(int state); +void _NSSetLogCStringFunction(void(*)(const char*, unsigned, BOOL)); + // short names typedef int (*GetterFunc)(); typedef bool (*SetterFunc)(int); @@ -92,6 +94,19 @@ void check_power_on_for(const char *command) { eprintf("Power is required to be on for %s command\n", command); } +const char *filter_out_ns_log[] = { + "-[IOBluetoothDeviceInquiry initWithDelegate:]", + "-[IOBluetoothDeviceInquiry dealloc]", +}; + +void CustomNSLogOutput(const char* message, __unused unsigned length, __unused BOOL withSysLogBanner) { + for (size_t i = 0, _i = sizeof(filter_out_ns_log) / sizeof(filter_out_ns_log[0]); i < _i; i++) { + if (strstr(message, filter_out_ns_log[i]) != NULL) return; + } + + eprintf("%s\n", message); +} + void usage(FILE *io) { static const char *lines[] = { ("blueutil v" VERSION), @@ -727,6 +742,8 @@ int main(int argc, char *argv[]) { } } + _NSSetLogCStringFunction(CustomNSLogOutput); + if (!BTAvaliable()) { eprintf("Error: Bluetooth not available!\n"); return EX_UNAVAILABLE;