JLConsoleLog 是壹款強大的App內建工具,可以用來幫助Swift開發者在開發和生產環境下打印log信息。在解bug時,妳不會在非調試環境下錯過關鍵和有用的log。妳也可以把他集成到妳的後門調試工具中,它能幫助妳解決很多棘手的問題。
JLConsoleLog支持3種顯示模式—— Floating , Bubble 和 FullScreen 。
在浮動模式下在選項欄上有4個按鈕。第壹個按鈕是設置按鈕,裏面包含清空所有log,過濾分類和等級的選項。第二個按鈕用來切換浮動和全屏模式。點擊第三個按鈕,控制臺會變成壹個半透明的浮動氣泡,並只顯示錯誤和警告數量。最後壹個是關閉按鈕。
浮動控制臺會在無操作的5秒後自動變成半透明模式。此外,妳可以拖動浮動控制臺和氣泡來避免遮擋。
當妳點擊每條log的cell時,就會進入log的詳情頁面。
性能監控是壹個新的功能,妳可以通過點擊氣泡按鈕獲取監控圖表。支持監控CPU、內存和幀率。
** JLConsoleController** 是開放給開發者的控制臺控制器。它包括壹個***享的實例。妳可以通過它來設置 style (展示模式)和 logEnable (開啟log)。當妳設置它的style時,會根據妳給定的模式立即顯示。像這樣:
當 logEnable 為true的時候,控制臺才會收集log,反之亦然。
這裏提供了壹些列類型的日誌。
** JLConsoleLogLevel**是壹個枚舉,列舉了壹系列的等級。警告和錯誤的數量會被展示在選項欄和氣泡上。
** JLConsoleLogCategory** 是壹個String的別名,用來給妳需要打log的業務進行分類。妳可以自定義自己的Category來滿足妳的需求,例如視頻、頁面追蹤、商品詳情等等。如果妳需要可以過濾Category,妳必須用這種方式註冊:
參數 contextData 是壹個可被序列化的字典。其數據會被在詳情頁中以Json的形式展現。
參數 formats 是壹個variadic參數型的String。其第壹個參數值會被當做cell的標題展示在控制臺中。
如果 needPrint 為true,在調試環境下log的信息會被打印在Xcode的控制臺中。
除此之外,JLConsoleController提供了 followingAction 閉包,可以在使用JLConsoleLog記錄日誌後進行其他的操作。例如,妳可以在 followingAction 閉包進行Firebase或者友盟等埋點追蹤。 同時,不要忘了妳需要在記錄log時,將 hasFollowingAction 設為true。
上面是以壹個錯誤日誌為例。
JLConsoleLog提供了壹個性能監控。妳可以這樣開啟它。
此項目的Github地址是 /jacklandrin/JLConsoleLog
PerformanceMonitor
/2020/04/28/jlconsolelog/
JLConsoleLog is an awesome tool In-App to help swift developer log information in both development and production environment. You won’t miss any key and useful logs about the bugs in non-debug mode. You also can integrate it in your project’s backdoor toolkit, it will help you solve vital issues.
JLConsoleLog supports three types of style (display mode) — Floating , Bubble and FullScreen
There are four buttons on the option view of floating mode. The first button is setting button where you can clear all logs from this console, filter categories and levels. The second one is for switching between floating and fullscreen mode. If the third one is pressed, the console will be a translucent bubble that only displays warning and error count. The last one is close button.
The floating console could become translucent automatically after 5s, if you don’t touch it. Additionally, you can drag floating console and bubble to anywhere to avoid disturb you.
While you tap a log cell, you can enter the detail page of log.
Performance monitor is a new function. You can invoke a monitor chart from bubble button now. It supports CPU, Memory and FPS.
The JLConsoleController is the console’s controller opened for developers. It contains a shared instance. You could set style and logEnabled via it. While you set its style (display mode), the console will immediately show in terms of you given. Like this:
If logEnabled is true, the console will collect log data, vice verse.
A series functions are offered to log.
The JLConsoleLogLevel is an enum to sort by different levels. The numbers of warning and error are displayed on option view and bubble.
The JLConsoleLogCategory is your business category and is an alias of String . You can define your own categories met your demand, such as Video, TrackPage, Commodity Detail… If you need to filter your categories, you must register in this way in your code:
The parameter, contextData , is a serializable Dictionary. The data will be shown on the detail page in Json.
The parameters, formats , is variadic parameters of String. The first value will be shown on the cell’s title in console.
If needPrint equals true, the log information will print in your Xcode console in Debug environment.
Otherwise, JLConsoleController provides a followingAction to operate other actions when you finish logging. For example, you can send a track point log to statistics server such as Firebase in followingAction closure. Meanwhile, please don’t forget to set hasFollowingAction as true while you log.
This is an error log example.
JLConsoleLog provides a performance monitor. You can add these to turn on it.
The git address is /jacklandrin/JLConsoleLog
PerformanceMonitor