Skip to content

Comments

Fix Darwin OSLog composition failure in historical logs#594

Merged
oshai merged 7 commits intomasterfrom
fixdarwin
Jan 9, 2026
Merged

Fix Darwin OSLog composition failure in historical logs#594
oshai merged 7 commits intomasterfrom
fixdarwin

Conversation

@oshai
Copy link
Owner

@oshai oshai commented Jan 9, 2026

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.

    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:
    log show --predicate 'processImagePath CONTAINS "test.kexe"' --info --style syslog --last 5m
  • Confirmed output contains the log message instead of <compose failure>.

Verification Log

Before Fix (Reproduction)

$ ./gradlew cleanMacosArm64Test macosArm64Test --tests Issue588Test -I fix_repo.gradle
...

Task :macosArm64Test
...
kotlin-logging: initializing... active logger factory: DarwinLoggerFactory
Logger class: DarwinKLogger
Logged message with UUID: 851BE2BC-15D2-4623-A910-7BB6E7E76BE7
...
BUILD SUCCESSFUL

$ log show --predicate 'processImagePath CONTAINS "test.kexe"' --info --style syslog --last 5m
Filtering the log data using "processImagePath CONTAINS "test.kexe""
Timestamp (process)[PID]
2026-01-09 08:29:14.011468+0200 localhost test.kexe[87338]: <compose failure [UUID]>
2026-01-09 08:29:14.011517+0200 localhost test.kexe[87338]: <compose failure [UUID]>
2026-01-09 08:29:14.011523+0200 localhost test.kexe[87338]: <compose failure [UUID]>
2026-01-09 08:29:14.012117+0200 localhost test.kexe[87338]: <compose failure [UUID]>
2026-01-09 08:29:14.012331+0200 localhost test.kexe[87338]: [issue588:repro] <compose failure [UUID]>
2026-01-09 08:29:14.012337+0200 localhost test.kexe[87338]: [issue588:repro] <compose failure [UUID]>

After Fix (Verification)

$ ./gradlew cleanMacosArm64Test macosArm64Test --tests Issue588Test -I fix_repo.gradle
...

Task :macosArm64Test
...
kotlin-logging: initializing... active logger factory: DarwinLoggerFactory
Logger class: DarwinKLogger
Logged message with UUID: F45C6A5D-EA44-49F4-BA75-7DD9BFD3AF12
...
BUILD SUCCESSFUL

$ log show --predicate 'processImagePath CONTAINS "test.kexe"' --info --style syslog --last 5m
Filtering the log data using "processImagePath CONTAINS "test.kexe""
Timestamp (process)[PID]
2026-01-09 08:36:46.297674+0200 localhost test.kexe[88330]: [issue588:repro] Test message execution F45C6A5D-EA44-49F4-BA75-7DD9BFD3AF12
2026-01-09 08:36:46.297683+0200 localhost test.kexe[88330]: [issue588:repro] Test error execution F45C6A5D-EA44-49F4-BA75-7DD9BFD3AF12

@oshai oshai merged commit 36e56c3 into master Jan 9, 2026
9 checks passed
@oshai oshai deleted the fixdarwin branch January 9, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Darwin] OSLog: Historical logs show <compose failure>

1 participant