Created
June 14, 2018 16:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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