Skip to content

Instantly share code, notes, and snippets.

@gregttn
Created March 30, 2016 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregttn/b6a6cfdda4715828e6ad31befb21fa01 to your computer and use it in GitHub Desktop.
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.
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