Added Some screens here.
OSLog makes it possible to log per category, which can be used to filter logs using the Console app. By defining a small extension you can easily adopt multiple categories
import os.log
extension OSLog {
private static var subsystem = Bundle.main.bundleIdentifier!
// Logs the view cycles like viewDidLoad.
static let viewCycle = OSLog(subsystem: subsystem, category: "viewcycle")
// Logs the view User Details like viewDidLoad.
static let userDetails = OSLog(subsystem: subsystem, category: "userdetails")
// Logs the User Email like viewDidLoad.
static let userEmail = OSLog(subsystem: subsystem, category: "useremail")
// Logs the User Account like viewDidLoad.
static let userAccount = OSLog(subsystem: subsystem, category: "useraccount")
}
This extension uses the bundle identifier of the app and creates a static instance for each category. In this case, we have a view cycle category, which we can use to log in our app:
//All Types of Logs
os_log("View did load!", log: OSLog.viewCycle, type: .info)
os_log("View did load!", log: OSLog.viewCycle, type: .default)
os_log("View did load!", log: OSLog.viewCycle, type: .error)
os_log("View did load!", log: OSLog.viewCycle, type: .debug)
//Try this type of Logs
os_log("User Full Name %{PUBLIC}@ logged in", log: OSLog.userDetails, type: .info, "Pawan Kumar")
os_log("User Last Name %{PUBLIC}@ logged in", log: OSLog.userDetails, type: .info, "Sharma")
os_log("User Email %{PRIVATE}@ logged in", log: OSLog.userEmail, type: .debug, "xyz@gmail.com")
os_log("User Account %{PRIVATE}@ logged in", log: OSLog.userAccount, type: .debug, "iOS Developer")
The OSLog API requires to pass in an OSLogType which can be used to automatically send messages at the appropriate level.
The default log level, which is not really telling anything about the logging. It’s better to be specific by using the other log levels.
Call this function to capture information that may be helpful, but isn’t essential, for troubleshooting.
Debug-level messages are intended for use in a development environment while actively debugging.
Error-level messages are intended for reporting critical errors and failures.
Fault-level messages are intended for capturing system-level or multi-process errors only.
This code is distributed under the terms and conditions of the MIT license.
A brief summary of each this release can be found in the CHANGELOG.