As lead of an iOS app team, what unified logging convention would you set for subsystems, categories, levels and privacy, and what does each rule trade away?
answer
- four choices on every line
- bundle ID, closed category list
- notice for what support must read
- public needs a reason in review
- the store purges old entries
basics
~20 sUse the bundle ID as subsystem, a closed list of feature categories declared once, notice for steps support must read, error and fault for real problems, default privacy for user data with hash masks for correlation, and review every .public.
solid answer
~40 sI would fix four things. Subsystem: the bundle ID, with a separate one per extension process. Categories: a closed list declared once as static `Logger` constants, reused by `OSSignposter(logger:)`. Levels: steps support must read after a failure at `notice`, handled failures at `error`, broken assumptions at `fault`, detail at `debug`, because only notice and above persist and the store purges old entries, so noise evicts useful lines. Privacy: keep `.auto` for strings, never `.public` on user data, `.private(mask: .hash)` for identifiers that must correlate, explicit `.private` on identifying integers, and a stated reason for every `.public` in review. Each rule trades something: more categories fragment a failure, more redaction slows diagnosis, more notice lines churn the store.
go deeper
Recall that a team convention covers subsystem, category, level and privacy, and that print stays out of shipping code.
Explain how a closed category list and shared static loggers make predicates reliable, and why signposts reuse the same logger.
Back each rule with behaviour you have seen: purged stores, unpersisted debug lines, integers shown under .auto, hashes valid within one process.
Own the trade-offs: subsystem granularity against support simplicity, notice volume against history length, and redaction against diagnosis speed.
## What the convention has to settle Unified logging gives every engineer the same few choices on every line: which subsystem, which category, which level, and which privacy option for each value. Left to individual taste, the result is a log nobody can filter, a persisted store full of noise, and personal data marked `.public` "just for now". A lead's convention answers four questions and states what each answer costs. ## Subsystems - **One subsystem per app, usually the bundle ID.** Apple's `Logger` documentation says that is the typical value, and one predicate then captures the whole app. - **A separate subsystem per process** when the app ships extensions. Apple's guide suggests a different subsystem string for each additional process an app uses; an extension runs as its own process, so this lets support separate a widget from the main app. The cost: one subsystem is simpler, while more subsystems separate processes but require support to know the list. ## Categories - Keep a **closed list** of categories, one per feature or layer, declared once as static `Logger` constants so nobody invents `"Networking"`, `"network"` and `"net"` in the same week. - Signpost with `OSSignposter(logger:)` so a feature's intervals share its log lines' subsystem and category. - Remember that filtering by category should be combined with the subsystem. The cost: too few categories and a filter returns everything; too many and a failure spans five of them. ## Levels | Rule | What it buys | What it costs | |---|---|---| | Support-relevant steps at `notice` | they persist and appear in `log show` by default | they use space in a store that purges old entries | | Handled failures at `error`, broken assumptions at `fault` | a level filter finds real problems | fault often captures extra information, so it costs more | | Verbose detail at `debug` | very low overhead, in memory only | gone from any archive taken later | | `info` treated as optional | no false expectations | only persisted when the log tool collects it | The judgment here is volume: chatty notice lines evict the older lines support actually needs, while too little at notice leaves a field failure with no trail. ## Privacy 1. Leave `.auto` as the default for strings and objects; never mark user data `.public`. 2. Log identifiers that support must correlate with `.private(mask: .hash)`, knowing Apple describes the hash as unique for the current process. 3. Mark identifying **numbers** `.private` explicitly, because `.auto` shows integers. 4. Require a stated reason in review for every `.public`. The cost: more redaction means harder diagnosis, and no runtime switch exists, since the privacy argument must be a static member; debug-only visibility needs `#if DEBUG` and two calls. ## Enforcing it - One file owns the subsystem constant and the category list. - A linter rule or review checklist rejects `print` and `Logger()` without a subsystem in shipping code. - Support documentation names the route to logs, `log collect --device` from a Mac or an in-app export with `OSLogStore(scope: .currentProcessIdentifier)`, so engineers know which lines must be at notice to be found. ## A sample rule sheet For the boat-rental app, the whole convention fits on one page: 1. Subsystem `com.example.boatrental`; the widget extension uses its own. 2. Categories: `dock-checkin`, `bluetooth`, `payments`, `account`, nothing else without review. 3. Notice for each check-in step, error for each failed unlock, fault for impossible lock states, debug for packet detail. 4. Renter IDs with `.private(mask: .hash)`; firmware versions and error codes `.public`; everything else left at the default. 5. One signposted interval per unlock attempt, named `Unlock`, under the `dock-checkin` logger. There is no single right convention. A small app may live happily with one subsystem and five categories; an app with several extensions and a support desk needs the per-process split and the review rule for `.public`. What a lead owns is writing the trade-offs down so they are applied the same way by everyone.
- Should every app extension log under the app's subsystem?It is a trade-off. One subsystem lets a single predicate catch everything; a subsystem per process, which Apple's guide suggests when an app spawns additional processes, lets support separate a widget's lines from the app's. Teams with a support desk usually prefer the split, provided the list is documented.
- Engineers want renter IDs visible in debug builds; how do you allow that within the convention?The privacy argument must be a static `OSLogPrivacy` member, so there is no runtime switch. Allow a `#if DEBUG` branch with a `.public` call and a release branch with `.private(mask: .hash)`, and require review to confirm the public branch cannot ship.
- How do you stop notice-level logging from growing until it hides what matters?Make notice a contract: only steps support needs to reconstruct a failure. Review new notice lines like API changes, keep packet-level detail at debug, and remember the persisted store purges old messages, so every extra line shortens the history support can see.
- Each engineer can name categories freely; consistency does not affect filtering
- Mark identifiers .public so support can correlate lines
- Logging everything at notice or error has no downside
- A runtime flag can switch privacy to public for support sessions
- One convention fits every app regardless of extensions and support needs