Skip to content

Instantly share code, notes, and snippets.

@yanil3500
Last active June 6, 2019 02:57
Show Gist options
  • Save yanil3500/e00d0428cc4e583e5de3682ee4409c13 to your computer and use it in GitHub Desktop.
Save yanil3500/e00d0428cc4e583e5de3682ee4409c13 to your computer and use it in GitHub Desktop.
Swift Helper Logger Class
//___FILEHEADER___
import Foundation
// To use this as a template, do the following:
// 1. Create the 'Custom' directory -> mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templates/Custom
// 2. Open Finder, CMD + G into this directory /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates
// 3. Open 'Source' directory and copy the Swift File.xctemplate
// 4. Paste the Swift File.xctemplate into to the 'Custom' directory from step 1
// 5. Rename the Swift File.xctemplate in the 'Custom' directory to the desired name for the template
// 6. Replace the '___FILEBASENAME___.swift' file in template directory with this file
// 7. Alternatively, edit the '___FILEBASENAME___.swift' to suit your needs
// This helper class is helpful for when the debugging output produced by the programmer is buried by the debugging output from the system.
// To see programmer debugging output only, do the following:
// 1. Use this Logger's log functions
// 2. Type [the name of your project] in the console pane (debug area) bottom-right filter.
class Logger {
private init () {}
private static let project : String = "___PROJECTNAME___"
static func log(_ string: String, label: String = "INFO"){
DispatchQueue.main.async {
print("[\(Logger.project)][\(label)]: \(string)")
}
}
static func info(_ string: String) {
Logger.log(string)
}
static func warning(_ string: String) {
Logger.log(string, label: "WARNING")
}
static func error(_ string: String) {
Logger.log(string, label: "ERROR")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment