JLConsoleLog
什么是 JLConsoleLog?
JLConsoleLog 是一款出色的应用程序内工具,帮助 Swift 开发者在开发和生产环境中记录信息。在非调试模式下,您不会错过任何关于 bug 的关键和有用的日志。您还可以将其集成到项目的后门工具包中,这将帮助您解决关键问题。
如何操作它?
JLConsoleLog 支持三种样式(显示模式)-- 浮动、气泡 和 全屏
浮动模式的选项卡中有四个按钮。第一个按钮是设置按钮,您可以从控制台清除所有日志、过滤类别和级别。第二个按钮用于在浮动模式和全屏模式之间切换。如果按下第三个按钮,控制台将变为半透明气泡,只显示警告和错误计数。最后一个按钮是关闭按钮。
如果您 5 秒内不触摸浮动控制台,它将自动变为半透明。此外,您可以拖动浮动控制台和气泡到任何地方,避免打扰。
当您点击日志单元格时,您可以进入日志的详细页面。
性能监控是一个新功能。您现在可以从气泡按钮中调用监控图表。
如何在您的项目中使用它?
JLConsoleController是为开发者打开的控制台控制器。它包含一个共享实例。您可以通过它设置样式和启用日志记录。当您设置其样式时(显示模式),控制台将立即按照您给出的方式显示。例如:
if JLConsoleController.shared.style == .Hidden {
JLConsoleController.shared.style = .Floating //show console in floating fashion
} else {
JLConsoleController.shared.style = .Hidden //hide console
}
如果启用日志记录为真,则控制台将收集日志数据,反之亦然。
JLConsoleController.shared.logEnabled = true
提供了一系列的日志记录功能。
func JLLevelLog(level: JLConsoleLogLevel, category: JLConsoleLogCategory, hasFollowingAction:Bool = false, needPrint:Bool = false, contextData:Dictionary<String,Any> , formats: String...)
func JLVerboseLog( category: JLConsoleLogCategory, hasFollowingAction:Bool = false, needPrint:Bool = false, contextData:Dictionary<String,Any> , formats: String...)
func JLDebugLog( category: JLConsoleLogCategory, hasFollowingAction:Bool = false, needPrint:Bool = false, contextData:Dictionary<String,Any> , formats: String...)
func JLInfoLog( category: JLConsoleLogCategory, hasFollowingAction:Bool = false, needPrint:Bool = false, contextData:Dictionary<String,Any> , formats: String...)
func JLWarningLog( category: JLConsoleLogCategory, hasFollowingAction:Bool = false, needPrint:Bool = false, contextData:Dictionary<String,Any> , formats: String...)
func JLErrorLog( category: JLConsoleLogCategory, hasFollowingAction:Bool = false, needPrint:Bool = false, contextData:Dictionary<String,Any> , formats: String...)
JLConsoleLogLevel是一个枚举,用于对不同级别进行排序。警告和错误的数量将在选项视图和气泡中显示。
JLConsoleLogCategory是您的业务类别,它是String的别名。您可以根据需求定义自己的类别,例如视频、跟踪页面、商品详情等。如果您需要筛选类别,您必须在代码中以这种方式注册:
let SubPageTestLog:JLConsoleLogCategory = "com.consolelog.mybusiness" //declare a category
JLConsoleController.shared.register(newCategory: SubPageTestLog) //register it
参数,上下文数据,是一个可序列化的字典。数据将以Json格式在详情页面显示。
参数,格式,是String的可变参数。第一个值将在控制台单元格的标题中显示。
如果需要打印等于true,则在调试环境中将日志信息打印到Xcode控制台。
否则,JLConsoleController提供了一个后续操作,在您完成日志记录后进行其他操作。例如,您可以在后续操作闭包中将跟踪点日志发送到统计服务器,例如Firebase。同时,请记住在记录时将具有后续操作设置为true。
JLErrorLog(category: SubPageTestLog, hasFollowingAction: true ,needPrint: true, contextData: ["test":5], formats: "Error!",#function,String(#line))
这是一个错误日志示例。
性能监控
JLConsoleLog提供了一个性能监控器。您可以添加这些来开启它。
JLConsoleController.shared.performanceMonitable = true
GIT地址:https://github.com/jacklandrin/JLConsoleLog
需求
- iOS 12
- Swift 5.2
- Xcode 11
参考
许可协议
MIT