Black Friday 2024 deal: 30% off our Swift and SwiftUI books! Learn more ...Black Friday 2024 deal:30% off our Swift and SwiftUI books >>

Filtering logs in Xcode 15

We have some great new features in the debug console in Xcode 15. I'm particularly excited about improved filtering functionality that makes it much easier to view console logs. In this post I'm going to highlight the main changes and show how we can take advantage of them.

To benefit from all the nice new features, we have to make sure that we are using unified logging and not print statements in our projects. For the demo purposes in this post, let's imagine that we have the following simple logs already in place.

import OSLog

...

let welcomeScreenLogger = Logger(subsystem: "MyTestApp", category: "WelcomeScreen")
let accountLogger = Logger(subsystem: "MyTestApp", category: "Account")
    
...

welcomeScreenLogger.info("Loading welcome screen data...")

...

welcomeScreenLogger.error("Loading error occurred: \(error)")

...

accountLogger.info("Logged in successfully")

...

accountLogger.fault("Something bad happened")

# Viewing metadata

Firstly, let's see how we can make Xcode show different kinds of metadata for logs to make it easier to find and read the messages that we are looking for.

In the case when all of our demo logs appear in the console, we are going to see them in the following way. The metadata is hidden by default and different log levels have different background color. Error logs are colored in yellow while fault logs are colored in red.

Screenshot showing console logs in Xcode 15

We can now choose what kind of metadata we want to see by pressing the "Metadata Options" button at the bottom of the console. For example, we can show type, timestamp and category of the logs by checking these checkboxes. The selected metadata will appear below the message for each log.

Screenshot showing console logs with metadata

If we want to see all of the metadata available for a singe log, we can click on that log first, and then press space on the keyboard. Xcode will show a popover with all the relevant information including the call site.

Screenshot showing info for an error log in Xcode

# Showing or hiding similar items

If we are interested in a particular log and want to see only items that are similar to it and hide the rest, we can do it by right-clicking on the log, then choosing the "Show Similar Items" option. There we can choose what information should be used as a filter. For example, if we only want to see the logs from the same category, we can select "Category 'WelcomeScreen'" as the filter.

Screenshot showing filtering option for similar logs

Once selected, the category filter will be automatically added in the filter bar at the bottom of the console. There, we can clear the filter if we want to see all the logs again.

Screenshot showing the category filter applied

If we want to hide only one type of logs and show everything else, we can right-click on a log and choose the "Hide Similar Items" option. For example, we can hide all of the info logs, to reduce the amount of noise in the console while we are focusing on errors and faults.

Screenshot showing filtering option for hiding similar logs
Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover

Black Friday 2024 offer: 30% off!$45$32

A detailed guide on gradually adopting SwiftUI in UIKit projects

Updated for iOS 18 and Xcode 16!

Integrating SwiftUI into UIKit Appsby Natalia Panferova

  • Upgrade your apps with new features like Swift Charts and Widgets
  • Support older iOS versions with effective backward-compatible strategies
  • Seamlessly bridge state and data between UIKit and SwiftUI using the latest APIs
Black Friday 2024 offer: 30% off!

A detailed guide on gradually adopting SwiftUI in UIKit projects

Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover

Integrating SwiftUI
into UIKit Apps

by Natalia Panferova

Updated for iOS 18 and Xcode 16!

$45$32

# Filtering by type

We can quickly filter logs by type from the quick filters option on the left of the filter bar. We can choose to only show errors or faults, for example.

Screenshot showing quick filtering options

In the same popover we can also access the filters that we recently applied.

# Entering filters in the filter bar

When entering a filter into the filter bar, we can make use of Xcode filtering suggestions. If we want to only show logs from a certain category, we can start typing the name in the filter bar and check the autocomplete options. For example, to quickly see all the logs for the Account component, I start typing "acc" and select Category == Account from Xcode suggestions.

Screenshot showing filter suggestions

If we are looking for a particular message, we can simply type a porting of the string into the filter bar. Only the logs that contain the string we typed will be shown.

Screenshot showing filtering by a string


If you're an experienced Swift developer looking to learn advanced techniques, check out my latest book Swift Gems. It’s packed with tips and tricks focused solely on the Swift language and Swift Standard Library. From optimizing collections and handling strings to mastering asynchronous programming and debugging, "Swift Gems" provides practical advice that will elevate your Swift development skills to the next level. Grab your copy and let's explore these advanced techniques together.

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Black Friday 2024 offer: 30% off!$35$25

100+ tips to take your Swift code to the next level

Swift Gemsby Natalia Panferova

  • Advanced Swift techniques for experienced developers bypassing basic tutorials
  • Curated, actionable tips ready for immediate integration into any Swift project
  • Strategies to improve code quality, structure, and performance across all platforms
Black Friday 2024 offer: 30% off!

100+ tips to take your Swift code to the next level

Swift Gems by Natalia Panferova book coverSwift Gems by Natalia Panferova book cover

Swift Gems

by Natalia Panferova

$35$25