Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment