ZCDebug
Swift 轻量级调试库。
方便的调试库。主要目标是减少开发者的调试时间。它易于使用和理解。版本 0.0.2 - 使用 Apple 原生 Logger。
调试函数
- _$c() - 无消息日志,显示调用信息。
- _$l(obj) - 正常日志,应用于所有普通日志(例如 API 的响应)
- _$lw(obj) - 警告日志,应用于数据不正确但应用程序可以继续工作的情况
- _$le(obj) - 错误日志,某些事情出错了,应该被修复。
- _$tf(obj) - 跟踪函数(仅适用于主线程),它显示系统调用此函数所需的时间
- _$fail(_ condition: Bool = true, reason: String) - 使应用程序崩溃(仅在调试模式下工作),应在使用例程中采用,例如,应用程序无法创建数据库。
使用方法
登录功能使用
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
_$l("This is regular debug")
_$lw("This is warning debug")
_$le("This is error debug")
return true
}
xCode控制台将显示
💬 17:34:43.560 AppDelegate [application(_:didFinishLaunchingWithOptions:)] : 26 ~~ This is regular debug
❗ 17:34:43.561 AppDelegate [application(_:didFinishLaunchingWithOptions:)] : 27 ~~ This is warning debug
❌ 17:34:43.561 AppDelegate [application(_:didFinishLaunchingWithOptions:)] : 28 ~~ This is warning debug
跟踪函数使用
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
_$tf()
sleep(2)
return true
}
xCode控制台将显示
💬 17:42:43.224 AppDelegate [application(_:didFinishLaunchingWithOptions:)] : 26 ~~ Start application(_:didFinishLaunchingWithOptions:)
💬 17:42:45.580 AppDelegate [application(_:didFinishLaunchingWithOptions:)] : 26 ~~ Finished application(_:didFinishLaunchingWithOptions:) in 2.35600805282593
断言函数使用:断言函数仅在调试模式下工作。
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
var x = 0, y = 1
_$fail(x < y, reason: "X should be less than Y")// or just _$fail(reason: "Data Base can not be migrated")
return true
}
xCode控制台将显示
❌ 17:46:03.708 AppDelegate [application(_:didFinishLaunchingWithOptions:)] : 27 ~~ ❗❗❗ fail: X should be less than Y❗❗❗
0 TestApplication 0x000000010aab49f7 _T011TestApplication6_$failySb_SS6reasonS2SSitF + 231
1 TestApplication 0x000000010ac116dc _T011TestApplication11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0F16LaunchOptionsKeyVypGSg022didFinishLaunchingWithI0tF + 348
2 TestApplication 0x000000010ac133ba _T011TestApplication11AppDelegateC11applicationSbSo13UIApplicationC_s10DictionaryVySC0F16LaunchOptionsKeyVypGSg022didFinishLaunchingWithI0tFTo + 186
3 UIKit 0x000000010d3db75b -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 278
4 UIKit 0x000000010d3dd1d2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4123
5 UIKit 0x000000010d3e262b -[UIApplication _runWithMainScene:transitionContext:completion:] + 1677
6 UIKit 0x000000010d7a4e4a __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 866
7 UIKit 0x000000010db77909 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
8 UIKit 0x000000010d7a4a86 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
9 UIKit 0x000000010d7a52a7 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 675
10 UIKit 0x000000010e1164d4 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 299
11 UIKit 0x000000010e11636e -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
12 UIKit 0x000000010ddfa62d __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
13 UIKit 0x000000010dff5387 _performActionsWithDelayForTransitionContext + 100
14 UIKit 0x000000010ddfa4f7 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
15 UIKit 0x000000010db76fb0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
16 UIKit 0x000000010d3e0f0c -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515
17 UIKit 0x000000010d9b3a97 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
18 FrontBoardServices 0x0000000116e7e2f3 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 331
19 FrontBoardServices 0x0000000116e86cfa __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 225
20 libdispatch.dylib 0x00000001129e7848 _dispatch_client_callout + 8
21 libdispatch.dylib 0x00000001129ece14 _dispatch_block_invoke_direct + 592
22 FrontBoardServices 0x0000000116eb2470 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
23 FrontBoardServices 0x0000000116eb212e -[FBSSerialQueue _performNext] + 439
24 FrontBoardServices 0x0000000116eb268e -[FBSSerialQueue _performNextFromRunLoopSource] + 45
25 CoreFoundation 0x0000000110bc0bb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
26 CoreFoundation 0x0000000110ba54af __CFRunLoopDoSources0 + 271
27 CoreFoundation 0x0000000110ba4a6f __CFRunLoopRun + 1263
28 CoreFoundation 0x0000000110ba430b CFRunLoopRunSpecific + 635
29 GraphicsServices 0x0000000113feaa73 GSEventRunModal + 62
30 UIKit 0x000000010d3e40b7 UIApplicationMain + 159
31 TestApplication 0x000000010ac19927 main + 55
32 libdyld.dylib 0x0000000112a64955 start + 1