Skip to content

Instantly share code, notes, and snippets.

@joncardasis
Created October 24, 2016 21:09
Show Gist options
  • Save joncardasis/6535cd7c423924b2731c87303e782bd1 to your computer and use it in GitHub Desktop.
Save joncardasis/6535cd7c423924b2731c87303e782bd1 to your computer and use it in GitHub Desktop.
A simple and quick logging file for Swift
//
// Logging.swift
// JCLogging-Swift
//
// Created by Cardasis, Jonathan (J.) on 8/29/16.
// Copyright © 2016 Jonathan Cardasis. All rights reserved.
//
import Foundation
/**
Prints only if building for DEBUG
*/
public func printd(items: Any...){
#if DEBUG
var context: String {
return items.map({ String($0) }).joinWithSeparator("")
}
Swift.print(context)
#endif
}
/**
Prints verbose information. Only prints if building for DEBUG
*/
public func printv(items: Any..., fileExecuter: String = #file, callingFunction: String = #function, executionLine: Int = #line){
#if DEBUG
let filename = NSURL(string: fileExecuter)?.URLByDeletingPathExtension?.lastPathComponent ?? ""
var context: String {
return items.map({ String($0) }).joinWithSeparator("")
}
Swift.print("[\(filename).\(callingFunction): Line \(executionLine)] ", separator: " ", terminator: "")
Swift.print(context)
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment