Last active
July 18, 2016 07:04
-
-
Save c0ming/d249802f6eecbfbd265675f928acbf41 to your computer and use it in GitHub Desktop.
Swifty Console Log
This file contains hidden or 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
// | |
// Console.swift | |
// | |
// Created by c0ming on 16/7/15. | |
// Copyright © 2016 c0ming. All rights reserved. | |
// | |
import Foundation | |
private let dateFormatter: DateFormatter = { | |
let formatter = DateFormatter() | |
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS" | |
return formatter | |
}() | |
public class Console { | |
public static func log(_ messages: Any..., _ file: NSString = #file, _ line: Int = #line, _ function: String = #function) { | |
#if DEBUG | |
let timestamp = dateFormatter.string(from: Date()) | |
let className = file.components(separatedBy: "/").last!.replacingOccurrences(of: ".swift", with: "") | |
let separator = " | " | |
let message = messages.enumerated().map({ offset, element in | |
return (offset == messages.count - 1) ? "\(element)" : "\(element)" + separator | |
}).reduce("") { | |
$0 + $1 | |
} | |
print("\(timestamp) [\(className)] [#\(line)] [\(function)] \(message)") | |
#endif | |
} | |
} |
Author
c0ming
commented
Jul 18, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment