HouLogger
HouLogger 是一个用于日志记录和在本地磁盘保存日志文件的漂亮、轻量级的纯 Swift 库。
功能
- 漂亮的日志。
- 在本地磁盘上保存日志。
- 在 UIWindow 上显示日志。
- 记录用户 APP 版本。
- 记录用户更新 APP 版本历史。例如 1.0 -> 1.1 -> 1.5
- 记录用户设备信息。
开始使用 HouLogger
两个导入类
- BaseLogger:只是记录日志
- AdvancedLogger:BaseLogger 的子类。它提供了将日志保存到文件和在 UIWindow 和 UIView 上显示日志的能力
- LogTextView:显示日志的 UIView。
// configure in `application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool`
UserDefaults.standard.setAPPVersionAndHistory() // NOTE: Do not forget this line.
logger.configure([.debug, .fault, .error, .info, .normal])
// Usage
logI("info")
logD("debug")
logN("normal")
logE("Error String", theOSLog: .network)
logE(APIError.invalidURL, theOSLog: .network)
logF("fault", theOSLog: .test)
打印
⭐️😂: user
⭐️💩: AppDelegate [33], [application(_:didFinishLaunchingWithOptions:)]: code
⭐️🦋: #36, 12:57:26 PM: issue
⭐️❌: AppDelegate [35], [application(_:didFinishLaunchingWithOptions:)]: this is an error, error: The operation couldn’t be completed. (HouLogger_Example.AppDelegate.APIError error 0.)
更高级的示例
显示日志文本并保存日志文件到缓存目录
logger.configure([.debug, .fault, .error, .info, .normal], shouldShow: true, shouldCache: true)
在您的 UIWindow/UIView 中添加 LogTextView,例如:
if #available(iOS 11.0, *) {
window.addSubview(logTextView, constraints: [
UIView.anchorConstraintEqual(from: \UIView.topAnchor, to: \UIView.safeAreaLayoutGuide.topAnchor, constant: .defaultMargin),
UIView.anchorConstraintEqual(from: \UIView.leadingAnchor, to: \UIView.safeAreaLayoutGuide.leadingAnchor, constant: .defaultMargin),
UIView.anchorConstraintEqual(from: \UIView.bottomAnchor, to: \UIView.safeAreaLayoutGuide.bottomAnchor, constant: CGFloat.defaultMargin.negativeValue),
UIView.anchorConstraintEqual(from: \UIView.trailingAnchor, to: \UIView.safeAreaLayoutGuide.trailingAnchor, constant: CGFloat.defaultMargin.negativeValue),
])
} else {
window.addSubview(logTextView, constraints: [
UIView.anchorConstraintEqual(with: \UIView.topAnchor, constant: .defaultMargin),
UIView.anchorConstraintEqual(with: \UIView.leadingAnchor, constant: .defaultMargin),
UIView.anchorConstraintEqual(with: \UIView.bottomAnchor, constant: CGFloat.defaultMargin.negativeValue),
UIView.anchorConstraintEqual(with: \UIView.trailingAnchor, constant: CGFloat.defaultMargin.negativeValue),
])
}
}
添加自定义 JeOSLog
您可以在 BaseLogger.swift 文件中的 JeOSLog 枚举中添加新案例。
使用 HouLogger 配合控制台应用程序
需求
- iOS 10.0+
- Swift 4.0+
安装
HouLogger 可通过 CocoaPods 获取。要安装,请将以下行添加到您的 Podfile 中
pod 'HouLogger'
作者
许可
HouLogger 在 MIT 许可下可用。更多信息请参考 LICENSE 文件。