Skip to content

Commit

Permalink
stumbled upon _NSSetLogCStringFunction to hide IOBluetoothDeviceInqui…
Browse files Browse the repository at this point in the history
…ry debug messages
  • Loading branch information
toy committed Feb 2, 2025
1 parent dae3201 commit 1b63e06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions blueutil.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -727,6 +742,8 @@ int main(int argc, char *argv[]) {
}
}

_NSSetLogCStringFunction(CustomNSLogOutput);

if (!BTAvaliable()) {
eprintf("Error: Bluetooth not available!\n");
return EX_UNAVAILABLE;
Expand Down

0 comments on commit 1b63e06

Please sign in to comment.