Organised logging in Swift that can be searched is simple thanks to the built-in os_log. By storing our categories as an extension on OSLog we can access them using a short syntax.

This makes categories so much easier to specify and helps with auto-completion! 🎉

extension OSLog {
    static let logAuthentication = OSLog(subsystem: "com.myapp.App", category: "Auth")
    static let logDatabase = OSLog(subsystem: "com.myapp.App", category: "Database")
    static let logNetwork = OSLog(subsystem: "com.myapp.App", category: "Network")

os_log("User signed in: %@", log: .logAuthentication, type: .default, email)
os_log("Chat messages sync complete", log: .logNetwork, type: .info)
os_log("Chat messages saved successfully", log: .logDatabase, type: .debug)

Thanks for reading and happy coding! 🙏