Skip to content

Instantly share code, notes, and snippets.

@cbess
Last active September 2, 2021 07:25
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 cbess/8fa7b9e2330a07020541 to your computer and use it in GitHub Desktop.
Save cbess/8fa7b9e2330a07020541 to your computer and use it in GitHub Desktop.
Simple Logger class in Swift 4.x
import Foundation
/// Represents the Log facilities
struct Log {
/// Prints in debug only
static func debug(_ msg: String, line: Int = #line, fileName: String = #file, funcName: String = #function) {
#if DEBUG
let fname = (fileName as NSString).lastPathComponent
print("[\(fname) \(funcName):\(line)]", msg)
#endif
}
/// Prints an error message in debug only
static func error(_ msg: String, line: Int = #line, fileName: String = #file, funcName: String = #function) {
debug("ERROR: \(msg)!!", line: line, fileName: fileName, funcName: funcName)
}
/// Prints the debug mark for the line
static func mark(line: Int = #line, fileName: String = #file, funcName: String = #function) {
debug("called", line: line, fileName: fileName, funcName: funcName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment