Skip to content

feat(logging): add platform-independent file logging [WPB-26806]#5062

Open
MohamadJaara wants to merge 4 commits into
developfrom
mo/feat/platform-independed-file-logger
Open

feat(logging): add platform-independent file logging [WPB-26806]#5062
MohamadJaara wants to merge 4 commits into
developfrom
mo/feat/platform-independed-file-logger

Conversation

@MohamadJaara

@MohamadJaara MohamadJaara commented Jul 16, 2026

Copy link
Copy Markdown
Member

https://wearezeta.atlassian.net/browse/WPB-26806

Add a file logger that does not depend on Android Logcat.

On some devices, Logcat is disabled or unavailable. The previous log collection flow could therefore produce empty 0 B files, leaving support teams without useful diagnostic information.

How to reproduce

  1. Run the app on a device where Logcat access is disabled or restricted.
  2. Use the app and generate logs.
  3. Export the diagnostic logs.
  4. The resulting log files may be empty.

What changed

  • Added a Kermit-backed file log writer.
  • Writes application and Kalium logs directly to a file instead of collecting them from Logcat.
  • Captures AVS and CoreCrypto logs that Kalium forwards through its registered Kermit callbacks.
  • Supports starting, stopping, flushing, clearing, and rotating log files.
  • Compresses rotated files using gzip.
  • Uses unique archive names to prevent rotations from overwriting each other.
  • Preserves uncompressed logs when compression fails so they can be recovered later.
  • Recovers incomplete rotations when the logger starts again.
  • Prevents an in-progress rotation from recreating files after logs have been cleared.
  • Flushes pending logs on low-memory callbacks without permanently stopping the logger.
  • Uses the shared Kalium logger configuration as the single source of truth for the log level.
  • Keeps the implementation behind USE_PLATFORM_INDEPENDENT_FILE_LOGGER for controlled rollout.

Logging flow

flowchart LR
    App["Application logs"] --> Kermit["Kermit"]
    Kalium["Kalium logs"] --> Kermit
    AVS["AVS native callback"] --> Kalium
    CoreCrypto["CoreCrypto native callback"] --> Kalium
    Kermit --> Writer["Platform-independent file writer"]
    Writer --> Active["Active log file"]
    Active --> Rotation["Rotation and gzip compression"]
    Rotation --> Export["Diagnostic log export"]
Loading

Result

Diagnostic log files no longer rely on Logcat being available. Devices with restricted or disabled Logcat can still produce useful application and supported native-library logs.

Notes

  • CoreCrypto currently forwards native logs starting at WARN.
  • Native output written directly to Logcat or stderr without going through the registered Kalium callbacks is outside the scope of this logger.
  • The legacy Logcat-based implementation remains available while the new logger is rolled out through the feature flag.

@pull-request-size

Copy link
Copy Markdown

Ups 🫰🟨

This PR is too big. Please try to break it up into smaller PRs.

@MohamadJaara MohamadJaara changed the title feat(logging): add platform-independent file logging feat(logging): add platform-independent file logging [WPB-26806] Jul 16, 2026
const val MILLIS_SUFFIX_LENGTH = 4
const val HUNDRED_MILLIS = 100
const val TEN_MILLIS = 10
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part need carfull review in case i missed something
it does call System::currentTimeMillis and cache the the prefix and for each log line calculate only the ms
meaning the parsing for the full date is only one time per second and the rest only MS is added to the end
the next second it will parsed again

if there is a better and more efficient way to do so let me know

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.25424% with 73 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.98%. Comparing base (fba8549) to head (9186bb8).

Files with missing lines Patch % Lines
...d/util/logging/PlatformIndependentLogFileWriter.kt 76.37% 29 Missing and 27 partials ⚠️
...rc/main/kotlin/com/wire/android/WireApplication.kt 42.10% 11 Missing ⚠️
...om/wire/android/ui/debug/LogManagementViewModel.kt 0.00% 2 Missing ⚠️
...in/com/wire/android/ui/debug/UserDebugViewModel.kt 0.00% 2 Missing ⚠️
...com/wire/android/util/logging/LogFileWriterImpl.kt 71.42% 1 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (75.25%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5062      +/-   ##
===========================================
+ Coverage    49.44%   49.98%   +0.54%     
===========================================
  Files          655      659       +4     
  Lines        23703    23980     +277     
  Branches      3659     3705      +46     
===========================================
+ Hits         11720    11987     +267     
+ Misses       10889    10870      -19     
- Partials      1094     1123      +29     
Files with missing lines Coverage Δ
...lin/com/wire/android/util/logging/LogFileWriter.kt 0.00% <ø> (ø)
.../wire/android/util/logging/LogFileWriterFactory.kt 100.00% <100.00%> (ø)
.../android/util/logging/LogLineTimestampFormatter.kt 100.00% <100.00%> (ø)
.../logging/PlatformIndependentLogFileWriterConfig.kt 100.00% <100.00%> (ø)
...om/wire/android/ui/debug/LogManagementViewModel.kt 0.00% <0.00%> (ø)
...in/com/wire/android/ui/debug/UserDebugViewModel.kt 76.74% <0.00%> (+76.74%) ⬆️
...com/wire/android/util/logging/LogFileWriterImpl.kt 8.77% <71.42%> (+8.77%) ⬆️
...rc/main/kotlin/com/wire/android/WireApplication.kt 5.21% <42.10%> (+1.29%) ⬆️
...d/util/logging/PlatformIndependentLogFileWriter.kt 76.37% <76.37%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fba8549...9186bb8. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant