Skip to content

feat: os_log for logging output#278

Merged
NathanWalker merged 1 commit into
mainfrom
feat/improved-os-log
Aug 22, 2025
Merged

feat: os_log for logging output#278
NathanWalker merged 1 commit into
mainfrom
feat/improved-os-log

Conversation

@NathanWalker

@NathanWalker NathanWalker commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

os_log landed in Apple SDKs with iOS 10.0, macOS 10.12, tvOS 10.0 and watchOS 3.0 (Xcode 8+).
https://developer.apple.com/documentation/os/generating-log-messages-from-your-code?language=objc

Another good reference:
https://www.donnywals.com/modern-logging-with-the-oslog-framework-in-swift/

This gracefully falls back to NSLog as needed.

Through os_log, we now use standard {public} for console logs per os_log conventions.
This fixes Xcode 26 <private> device log output.

Here’s why os_log is better than NSLog:

  1. Performance (huge)
  • Deferred formatting: strings aren’t built if the log is disabled, so “off” logs are near-zero cost.
  • Binary, lossless storage: logs go to efficient shared buffers instead of synchronous stderr I/O.
  • Selective enablement: you can turn on just a subsystem/category at runtime without paying global cost.
  1. Privacy & Security
  • Field-level redaction: mark values as .private (default in Swift Logger) or .public, so PII won’t leak in production or shared sysdiagnoses.
  • Compile-time format safety: avoids format-string injection mistakes common with printf-style APIs.
  • Deployment-safe: you can leave logs in release builds without exposing sensitive data.
  1. Structure & Control
  • Subsystem & category: organize logs (com.yourco.app / network, ui, etc.) so you can filter and toggle precisely.
  • Levels with semantics: debug, info, default, error, fault—with different capture/retention behavior on device.
  1. First-class tooling
  • Console.app & log CLI: query, filter, and correlate across processes and devices.
  • Instruments integration: signposts let you time intervals and visualize them alongside CPU, memory, and networking.
  1. Future-proof API
  • Apple’s modern Swift overlay (Logger in OSLog) keeps improving (better interpolation, stronger typing, richer privacy controls). NSLog isn’t evolving.
@NathanWalker NathanWalker merged commit 3c5d894 into main Aug 22, 2025
7 checks passed
@NathanWalker NathanWalker deleted the feat/improved-os-log branch August 24, 2025 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant