RaLog
是一个轻量级、高度可定制、面向协议的日志框架。
通过使用框架提供的类型或自定义管理类,您可以快速构建自己的日志组件。
先决条件
- 运行 iOS 10 及以上版本的设备。
- 使用 Xcode 10 及以上版本编译。
- Swift 5.0 及以上版本。
安装
CocoaPods
pod 'RaLog'
Swift 包管理器
.Package(url: "https://github.com/RakuyoKit/RaLog.git", ...)
特性
- 开箱即用,易于配置。
- 打印对象或值,如同
print
或NSLog
。 - 提供两种缓存模式:**磁盘缓存** 和 **内存缓存**。
- 支持通过文件或日志类别进行 **过滤** 日志。
- **面向协议**,提供极高的自由度来自定义日志操作。
- 可用于与 ColaCup 一起查看日志数据。
用法
有关相关内容,请参阅 wiki:[快速开始](https://github.com/RakuyoKit/RaLog/wiki/Quick-start)。
预览
下面的代码演示了如何使用 RaLog
进行简单的日志打印。通过此代码,您将首次了解 RaLog
。
更多功能演示以及完整的示例代码可以在储存库提供的演示中找到(在
Examples
目录中)。
import UIKit
import RaLog
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
Log.appear(self)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
Log.disappear(self)
}
deinit {
Log.deinit(self)
}
override func viewDidLoad() {
super.viewDidLoad()
Log.debug("Note the output of the console")
Log.warning("Please note that the request is about to start!😎")
// Analog api request
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
if success {
Log.success("request success 🥳, content: api request succeeded")
} else {
Log.error("request failure 😢, error: \("some error")")
}
}
}
}
当即将访问 ViewController
控制器时,控制台将输出以下内容。
[↓ In `viewDidLoad()` of ViewController.swift:32 ↓]
[RaLog] 11:17:01:353 <👾 Debug> : Note the output of the console
[↓ In `viewDidLoad()` of ViewController.swift:36 ↓]
[RaLog] 11:17:01:356 <⚠️ Warning> : Please note that the request is about to start!😎
[↓ In `viewDidAppear(_:)` of ViewController.swift:16 ↓]
[RaLog] 11:17:01:370 <👋 Jump> : - Appear - ViewController
[↓ In `viewDidLoad()` of ViewController.swift:42 ↓]
[RaLog] 11:17:02:453 <✅ Success> : request success 🥳, content: api request succeeded
协议
RaLog
可在 MIT 许可证下使用。更多信息,请参阅 LICENSE。