Created
March 30, 2016 20:29
-
-
Save gregttn/b6a6cfdda4715828e6ad31befb21fa01 to your computer and use it in GitHub Desktop.
Code sample with usage of special literals to create logger which captures file, function, line and column when used.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum SomeError: ErrorType { | |
case Foo | |
case Bar | |
} | |
func willThrowException() throws { | |
throw SomeError.Foo | |
} | |
public class Logger { | |
static func log(msg: String, function: String = #function, file: String = #file, line: Int = #line, column: Int = #column) { | |
print("Message: \(msg)") | |
print("File: \(file); func: \(function); Line: \(line); Column: \(column)") | |
} | |
} | |
func doSomething() { | |
do { | |
try willThrowException() | |
} catch { | |
Logger.log("Horrible error caught!") | |
} | |
} | |
doSomething() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment