Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.