Skip to content

Instantly share code, notes, and snippets.

@acerosalazar
Created June 14, 2018 16:11
Show Gist options
  • Save acerosalazar/369be166ac02969391bf70d4833650b7 to your computer and use it in GitHub Desktop.
Save acerosalazar/369be166ac02969391bf70d4833650b7 to your computer and use it in GitHub Desktop.
A quick and simple logger for Mac. Useful for quick prototypes and POCs
import Foundation
private let logFile = "Library/Logs/\(Date().timeIntervalSince1970).log"
func log(_ message: String, file: String = #file, function: String = #function, line: Int = #line) {
let formattedMessage = "\(Date()) [\(URL(fileURLWithPath: file).lastPathComponent):\(function):\(line)] \(message)"
let task: Process = Process()
task.launchPath = "/bin/sh"
task.arguments = ["-c", "echo '\(formattedMessage)' >> '\(logFile)'"]
task.launch()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment