Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created November 7, 2015 17:22
Show Gist options
  • Select an option

  • Save kristopherjohnson/13a4e3781818d8cf66b3 to your computer and use it in GitHub Desktop.

Select an option

Save kristopherjohnson/13a4e3781818d8cf66b3 to your computer and use it in GitHub Desktop.
Simple logging functions for Swift
import Foundation
func logDebug(message: String,
function: String = __FUNCTION__, file: String = __FILE__, line: Int = __LINE__)
{
#if DEBUG
let filename = (file as NSString).lastPathComponent
let msg = "DEBUG: \(message) [\(function) \(filename):\(line)]"
NSLog("%@", msg);
#endif
}
func logError(message: String,
function: String = __FUNCTION__, file: String = __FILE__, line: Int = __LINE__)
{
let filename = (file as NSString).lastPathComponent
let msg = "ERROR: \(message) [\(function) \(filename):\(line)]"
NSLog("%@", msg);
}
@kristopherjohnson
Copy link
Author

Example output for logError("unable to find UserDefaults.plist")

2015-11-07 12:38:16.020 MyApp[2617:63696] ERROR: unable to find UserDefaults.plist [registerUserDefaults() UserDefaults.swift:35]

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