Created
February 6, 2019 08:22
-
-
Save yukin01/408af53b5cc60cc1e9e002bfc74444ac to your computer and use it in GitHub Desktop.
RxSwift の Debug に寄せたロガー(メインスレッド判定もできる)
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
enum Logger { | |
static let dateFormatter: DateFormatter = { | |
let df = DateFormatter() | |
df.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS" | |
return df | |
}() | |
static func log(_ item: String, file: String = #file, line: UInt = #line, function: String = #function) { | |
printLikeRxDebug(item, file, line, function) | |
} | |
static func isMainThread(file: String = #file, line: UInt = #line, function: String = #function) { | |
printLikeRxDebug("Main Thread: \(Thread.isMainThread)", file, line, function) | |
} | |
private static func printLikeRxDebug(_ item: String, _ file: String, _ line: UInt, _ function: String) { | |
let trimmedFile: String | |
if let lastIndex = file.lastIndex(of: "/") { | |
trimmedFile = String(file[file.index(after: lastIndex) ..< file.endIndex]) | |
} else { | |
trimmedFile = file | |
} | |
print("\(Logger.dateFormatter.string(from: Date())): \(trimmedFile):\(line) (\(function)) -> \(item)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment