You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 36e56c3
Browse filesBrowse the repository at this point in the historyBrowse files
Fix Darwin OSLog composition failure in historical logs (#594)
Fixes#588
## Description
This PR fixes an issue where logs on macOS (using `DarwinKLogger`) would show `<compose failure>` when viewed in historical logs (via `log show` or Console.app), despite appearing correctly in live logs (`log stream`).
The issue was caused by passing a dynamically allocated format string to `os_log`. Apple's `os_log` system requires the format string to be a C string literal located in the `__TEXT,__oslogstring` section of the binary for security and privacy (redaction) reasons. Wrappers or dynamic strings do not satisfy this requirement by default, causing the logging system to fail composition during archival.
## Solution
Implemented a C-interop solution to provide a valid static format string to `os_log`:
1. **Added C-Interop Definition (`oslog.def`)**: Created a C header/def file that defines a static inline function `kotlin_logging_os_log`.
```c
static inline void kotlin_logging_os_log(os_log_t log, os_log_type_t type, const char* message) {
os_log_with_type(log, type, "%{public}s", message);
}
```
This function uses `"%{public}s"` as a constant C string literal, which `clang` places in the correct section.
2. **Updated Build Configuration (`build.gradle.kts`)**: Configured all Darwin targets to include this C-interop definition.
3. **Updated `DarwinKLogger`**: Modified `DarwinKLogger.kt` to call `kotlin_logging_os_log` instead of `_os_log_internal`.
## Verification
- Added `Issue588Test` to reproduce the issue.
- Verified that logs are successfully persisted and readable using `log show`:
```bash
log show --predicate 'processImagePath CONTAINS "test.kexe"' --info --style syslog --last 5m
```
- Confirmed output contains the log message instead of `<compose failure>`.
0 commit comments