Skip to content

Instantly share code, notes, and snippets.

@SheldonWangRJT
Last active August 1, 2023 14:31
Show Gist options
  • Save SheldonWangRJT/9cecf3345e2224db482f49ea23217040 to your computer and use it in GitHub Desktop.
Save SheldonWangRJT/9cecf3345e2224db482f49ea23217040 to your computer and use it in GitHub Desktop.
OSLog in iOS is OP!(Over Power)

In WWDC23 https://developer.apple.com/videos/play/wwdc2023/10226/, the new debugging was released.

import OSLog

let logger = Logger(subsystem: "You system", category: "Account")

func doSomething() {

  logger.info("start")

  // ...
  
  if error {
    logger.error("got error with: \(error)")
  } else {
    logger.notice("succeed!")
  }
  
  // ...
}

By doing such thing, you will completely have a free categorized debugging window in Xcode, with category and subsystem filter.

The icing on the cake is that, you can see this in the instrument and this logger will also capture some trace info!

@SheldonWangRJT
Copy link
Author

You can see the debugger view in Xcode has different color for different logging level!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment