Skip to content

Choose a tag to compare

@samdeane samdeane released this 06 Nov 12:00
150da42

Logger 3.0 reworks channel control so that an app can drive it from its own UI or command layer. It replaces the actor-based channels with lighter Sendable classes and fixes several LoggerUI and persistence bugs. It breaks source compatibility with 2.x.

Channel control

  • Manager.setEnabled(_:), setAllEnabled(_:) and resetToDefaults() change channels in bulk. Each one saves the settings once and returns the previous state of only the channels it changed, which is what an undo action needs.
  • Channels take a default state: Channel("Name", default: .enabled). This replaces alwaysEnabled:. Only channels that differ from their default are saved, so turning a default-on channel off now persists.
  • The -logs argument accepts +name and -name to change saved states, a bare name to turn a channel on, and = to start from defaults.

LoggerUI

  • ChannelWatcher takes optional ChannelActions, so toggles can go through commands with undo instead of changing channels directly.
  • AllChannelsToggleView shows a mixed state when only some channels are on. A click turns them all on, or all off when they're already all on.
  • ResetChannelsButton is new, and LoggerChannelsView includes it.
  • Built-in labels come from the package's string catalog, with English fallbacks.
  • Watchers no longer retain themselves or compete for manager events, and controls update synchronously.

Concurrency and handlers

  • Channel, BasicHandler, OSLogHandler and StreamHandler are Sendable final classes instead of actors. Channel.enabled reads and writes synchronously.
  • Manager.events is a BroadcastSequence. Each subscriber gets .started first, followed by up to 256 buffered events. The stream ends only when Manager.shutdown() is called.
  • Manager.shutdown() stops every channel and waits for its output to drain.
  • tvOS uses OSLogHandler by default, like the other Apple platforms.

Breaking changes

  • alwaysEnabled: is replaced by default:.
  • Handler.shutdown() is removed; Channel.shutdown() is synchronous.
  • BasicHandler's closure type Logger is renamed Output.
  • YieldingSequence is no longer public.
  • ChannelToggleView is removed; use IndividualChannelsToggleView or a Toggle bound to watcher[enabled: id].
  • ManagerSettings reads and saves channel states instead of a set of enabled channels.
  • Saved channel choices are stored under a new key. Choices saved by 2.x are ignored, so channels start at their defaults once after upgrading.
  • FatalHandler must be @Sendable.

Full changes: #37 and #38.