Put Swift's Logger to good use: log everything & keep your console decluttered at the same time

Logger is an Apple framework available since Xcode 12 / iOS 14 and it’s the best way to track your app’s behavior.

It offers various levels of logging — info, warning, error, and more — which you sprinkle around your code so that you can monitor the flow in the console.

As your app grows, so does the volume of messages in the console.

Instead of filtering Xcode’s console by keywords or updating search parameters in the Console app, here’s how I keep my console de-cluttered:

  • Have a Logger instance for each “subsystem” of the app

  • Explicitly define (and use it) as an optional

  • Manage which of them are active in a single place - a file that extends Logger

My code here shows that I want to keep seeing health and shoes messages, but CoreData and onboarding are not needed at this time -- I just set them to nil, and comment out the original code.


The image above was generated with Snippet built by Seb Vidal and uses a background by the wonderfully creative Meng To.