Skip to content

Instantly share code, notes, and snippets.

@pxpgraphics
Created December 29, 2015 22:34
Show Gist options
  • Save pxpgraphics/a7e25c7673bda9c7d3f4 to your computer and use it in GitHub Desktop.
Save pxpgraphics/a7e25c7673bda9c7d3f4 to your computer and use it in GitHub Desktop.
// MARK: PXPLog
/**
Traditional C-style log with an optional message.
Prints file, line and function, by default, followed the messaage, if applicable.
- parameter file: The name of the file; defaults to the current localized file.
- parameter function: The name of the function; defaults to the function within which the call is made.
- parameter line: The line number; defaults to the line number within the file that the call is made.
*/
@transparent
@inline(__always)
public func PXPLog(
@autoclosure message: () -> String = String(),
file: StaticString = __FILE__,
function: StaticString = __FUNCTION__,
line: UInt = __LINE__
) {
let localizedFile = NSURL(string: String(file))?.lastPathComponent ?? "<Unknown file>"
print("\(localizedFile):\(line) #\(function) — \(message())")
}
@pxpgraphics
Copy link
Author

Sample console output:

PXPHomeDataManager.swift:38 #registerWithTableView — Registering table view: <UITableView: 0x7ff1b6808600; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x7ff1b4a146f0>; layer = <CALayer: 0x7ff1b4a0eb30>; contentOffset: {0, 0}; contentSize: {0, 7500}>

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