Skip to content

Commit

Permalink
Make src/platform/logging:stdio use log redirection on CHIP_PLATFORM_…
Browse files Browse the repository at this point in the history
…CUSTOM_LOG platforms.

This makes stdout logging work in unit tests on Darwin.
  • Loading branch information
ksperling-apple committed Nov 9, 2022
1 parent a174710 commit 6637c61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/platform/logging/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (current_os == "android") {
}
}

static_library("stdio") {
source_set("stdio") {
sources = [ "impl/stdio/Logging.cpp" ]

deps = [
Expand Down
13 changes: 13 additions & 0 deletions src/platform/logging/impl/stdio/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ void ENFORCE_FORMAT(3, 0) LogV(const char * module, uint8_t category, const char
} // namespace Platform
} // namespace Logging
} // namespace chip

// Use log redirection on platforms that don't use
// chip::Logging::Platform::LogV directly (e.g. Darwin)
#if CHIP_PLATFORM_CUSTOM_LOG

#include <lib/support/logging/CHIPLogging.h>

__attribute__((constructor)) static void CHIPConfigureStdoutLogging(void)
{
chip::Logging::SetLogRedirectCallback(chip::Logging::Platform::LogV);
}

#endif // CHIP_PLATFORM_CUSTOM_LOG

0 comments on commit 6637c61

Please sign in to comment.