Skip to content

Instantly share code, notes, and snippets.

@c0ming
Last active July 18, 2016 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c0ming/d249802f6eecbfbd265675f928acbf41 to your computer and use it in GitHub Desktop.
Save c0ming/d249802f6eecbfbd265675f928acbf41 to your computer and use it in GitHub Desktop.
Swifty Console Log
//
// 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
}
}
@c0ming
Copy link
Author

c0ming commented Jul 18, 2016

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    Console.log()
    Console.log(indexPath.row)
    Console.log(indexPath.section, indexPath.row, indexPath)
}

2016-07-18 14:35:52.655 [MyViewController] [#88] [collectionView(_:didSelectItemAt:)]
2016-07-18 14:35:52.655 [MyViewController] [#89] [collectionView(_:didSelectItemAt:)] 0
2016-07-18 14:35:52.655 [MyViewController] [#90] [collectionView(_:didSelectItemAt:)] 2 | 0 | [2, 0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment