//// LogViewController.swift// APIExample//// Created by 张乾泽 on 2020年4月17日.// Copyright © 2020 Agora Corp. All rights reserved.//import UIKitimport Foundationenum LogLevel {case info, warning, errorvar description: String {switch self {case .info: return "Info"case .warning: return "Warning"case .error: return "Error"}}}struct LogItem {var message:Stringvar level:LogLevelvar dateTime:Date}class LogUtils {static var logs:[LogItem] = []static func log(message: String, level: LogLevel) {LogUtils.logs.append(LogItem(message: message, level: level, dateTime: Date()))print("\(level.description): \(message)")}static func removeAll() {LogUtils.logs.removeAll()}}class LogViewController: AGViewController {}extension LogViewController: UITableViewDataSource {func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {return LogUtils.logs.count}func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {let cellIdentifier = "logCell"var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier)if cell == nil {cell = UITableViewCell(style: .default, reuseIdentifier: cellIdentifier)}let logitem = LogUtils.logs[indexPath.row]cell?.textLabel?.font = UIFont.systemFont(ofSize: 12)cell?.textLabel?.numberOfLines = 0;cell?.textLabel?.lineBreakMode = .byWordWrapping;let dateFormatterPrint = DateFormatter()dateFormatterPrint.dateFormat = "yyyy-MM-dd HH:mm:ss"cell?.textLabel?.text = "\(dateFormatterPrint.string(from: logitem.dateTime)) - \(logitem.level.description): \(logitem.message)"return cell!}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。