Skip to content

Instantly share code, notes, and snippets.

@phynet
Created February 12, 2018 09:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phynet/835165096157634ad375529377dfbb48 to your computer and use it in GitHub Desktop.
Save phynet/835165096157634ad375529377dfbb48 to your computer and use it in GitHub Desktop.
import Foundation
public struct Log
{
public static var isEnabled = true
public static func debug(_ m: @autoclosure ()->String, _ file: Any? = #file, _ f: String = #function, _ line: UInt = #line) {
print(m(), file ?? "", f, line)
}
public static func error(_ m: @autoclosure ()->String, _ file: Any? = #file, _ f: String = #function, _ line: UInt = #line) {
_print("🚨 \(m())", file, f, line)
}
public static func warn(_ m: @autoclosure ()->String, _ file: Any? = #file, _ f: String = #function, _ line: UInt = #line) {
_print("⚠️ \(m())", file, f, line)
}
private static func _print(_ m: String, _ file: Any? = #file, _ f: String = #function, _ line: UInt = #line) {
if isEnabled {
print("\(file ?? "").\(f):\(line) -\(m)")
}
}
}
//Use:
Log.warn("\(error)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment