docs: update logger

This commit is contained in:
2023-09-28 00:52:55 +08:00
parent dbe451d29c
commit fe2f5c802e
2 changed files with 70 additions and 70 deletions

View File

@@ -4,26 +4,26 @@
## Normal Logs
You can call `loggerD`, `loggerI`, `loggerW` to print normal logs to the console.
You can call `YLog.debug`, `YLog.info`, `YLog.warn` to print normal logs to the console.
The usage method is as follows.
> The following example
```kotlin
loggerD(msg = "This is a log")
YLog.debug(msg = "This is a log")
```
At this ponit, `YukiHookAPI` will call `android.util.Log` and log function in (Xposed) Host environment to print this log at the same time.
The default `TAG` of the log is the value you set in `YukiHookLogger.Configs.tag`.
The default `TAG` of the log is the value you set in `YLog.Configs.tag`.
You can also customize this value dynamically, but it is not recommended to modify `TAG` easily to prevent logs from being filtered.
> The following example
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log")
YLog.debug(tag = "YukiHookAPI", msg = "This is a log")
```
The printed result is as shown below.
@@ -31,21 +31,21 @@ The printed result is as shown below.
> The following example
```:no-line-numbers
[YukiHookAPI][D][host package name]--> This is a log
[YukiHookAPI][D][host package name] This is a log
```
You can also use `LoggerType` to customize the type of log printing.
You can also use `YLog.EnvType` to customize the type of log printing.
You can choose to use `android.util.Log` or the log function in the (Xposed) Host environment to print logs.
The default type is `LoggerType.BOTH`, which means that both methods are used to print logs.
The default type is `YLog.EnvType.BOTH`, which means that both methods are used to print logs.
For example we only use `android.util.Log` to print logs.
> The following example
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.LOGD)
YLog.debug(tag = "YukiHookAPI", msg = "This is a log", env = YLog.EnvType.LOGD)
```
Or just use the log function that in the (Xposed) Host environment to print the log, this method can only be used in the (Xposed) Host environment.
@@ -53,7 +53,7 @@ Or just use the log function that in the (Xposed) Host environment to print the
> The following example
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.XPOSED_ENVIRONMENT)
YLog.debug(tag = "YukiHookAPI", msg = "This is a log", env = YLog.EnvType.XPOSED_ENVIRONMENT)
```
If you want to intelligently distinguish the (Xposed) Host environment from the Module environment, you can write it in the following form.
@@ -61,27 +61,27 @@ If you want to intelligently distinguish the (Xposed) Host environment from the
> The following example
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.SCOPE)
YLog.debug(tag = "YukiHookAPI", msg = "This is a log", env = YLog.EnvType.SCOPE)
```
In this way, the API will intelligently select the specified method type to print this log in different environments.
::: tip
For more functions, please refer to [loggerD](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggerd-method), [loggerI](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggeri-method) and [loggerW](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggerw-method) methods.
For more functions, please refer to [YLog.debug](../public/com/highcapable/yukihookapi/hook/log/YLog#debug-method), [YLog.info](../public/com/highcapable/yukihookapi/hook/log/YLog#info-method) and [YLog.warn](../public/com/highcapable/yukihookapi/hook/log/YLog#warn-method) methods.
:::
## Error Logs
You can call `loggerE` to print `E` level logs to the console.
You can call `YLog.error` to print `E` level logs to the console.
The usage method is as follows.
> The following example
```kotlin
loggerE(msg = "This is an error")
YLog.error(msg = "This is an error")
```
The error log is the highest level, regardless of whether you have filtered only `E` level logs.
@@ -92,7 +92,7 @@ For error-level logging, you can also append an exception stack.
// Assume this is the exception that was thrown
val throwable = Throwable(...)
// Print log
loggerE(msg = "This is an error", e = throwable)
YLog.error(msg = "This is an error", e = throwable)
```
The printed result is as shown below.
@@ -100,7 +100,7 @@ The printed result is as shown below.
> The following example
```:no-line-numbers
[YukiHookAPI][E][host package name]--> This is an error
[YukiHookAPI][E][host package name] This is an error
```
At the same time, the log will help you print the entire exception stack.
@@ -109,25 +109,25 @@ At the same time, the log will help you print the entire exception stack.
```:no-line-numbers
java.lang.Throwable
at com.demo.Test.<init>(...)
at com.demo.Test.doTask(...)
at com.demo.Test.stop(...)
at com.demo.Test.init(...)
at a.a.a(...)
... 3 more
at com.demo.Test.<init>(...)
at com.demo.Test.doTask(...)
at com.demo.Test.stop(...)
at com.demo.Test.init(...)
at a.a.a(...)
... 3 more
```
In the error log, you can also use `LoggerType` to specify the method type currently used to print the log.
In the error log, you can also use `YLog.EnvType` to specify the method type currently used to print the log.
::: tip
For more functions, please refer to the [loggerE](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggere-method) method.
For more functions, please refer to the [YLog.error](../public/com/highcapable/yukihookapi/hook/log/YLog#error-method) method.
:::
## Save Logs and Custom Elements
You can save all currently printed logs directly to a file using the `YukiHookLogger.saveToFile` method.
You can save all currently printed logs directly to a file using the `YLog.saveToFile` method.
> The following example
@@ -135,25 +135,25 @@ You can save all currently printed logs directly to a file using the `YukiHookLo
// Please note
// The saved file path must have read and write permissions
// Otherwise an exception will be thrown
YukiHookLogger.saveToFile("/sdcard/Documents/debug_log.log")
YLog.saveToFile("/sdcard/Documents/debug_log.log")
```
You can also use `YukiHookLogger.contents` to get all the log file contents that have been printed so far.
You can also use `YLog.contents` to get all the log file contents that have been printed so far.
> The following example
```kotlin
// Get the contents of all log files that have been printed so far
val fileContent = YukiHookLogger.contents
val fileContent = YLog.contents
```
If you need an array of real-time log data structures, you can directly get the content of `YukiHookLogger.inMemoryData`.
If you need an array of real-time log data structures, you can directly get the content of `YLog.inMemoryData`.
> The following example
```kotlin
// Get the currently printed real-time log data structure array
YukiHookLogger.inMemoryData.forEach {
YLog.inMemoryData.forEach {
it.timestamp // Get timestamp
it.time // Get UTC time
it.priority // Get priority
@@ -169,19 +169,19 @@ If you want to format or save the obtained custom log data to a file, you only n
```kotlin
// Assume this is the custom log data you get
val data: ArrayList<YukiLoggerData>
val data: List<YLogData>
// Format log data to String
val dataString = YukiHookLogger.contents(data)
val dataString = YLog.contents(data)
// Save log data to file
// Please note
// The saved file path must have read and write permissions
// Otherwise an exception will be thrown
YukiHookLogger.saveToFile("/sdcard/Documents/debug_log.log", data)
YLog.saveToFile("/sdcard/Documents/debug_log.log", data)
```
::: danger
You need to enable **YukiHookLogger.Configs.isRecord** to get the contents of **YukiHookLogger.inMemoryData**.
You need to enable **YLog.Configs.isRecord** to get the contents of **YLog.inMemoryData**.
The obtained log data is isolated from each other in the Host App and the Module App's process.
@@ -193,7 +193,7 @@ If you only want to get log data in real time through Module App or Host App, Pl
:::
You can also use `YukiHookLogger.Configs.elements` to customize the elements that debug logs display externally.
You can also use `YLog.Configs.elements` to customize the elements that debug logs display externally.
This function requires `YukiHookAPI.Configs` to be configured in `onInit` of the Hook entry class.
@@ -211,6 +211,6 @@ override fun onInit() = configs {
::: tip
For more functions, please refer to [YukiHookLogger.inMemoryData](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#inmemorydata-field), [YukiHookLogger.contents](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#contents-field), [YukiHookLogger.contents](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#contents-method), [YukiHookLogger.saveToFile](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#savetofile-method) methods and [YukiHookLogger.Configs](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#configs-object).
For more functions, please refer to [YLog.inMemoryData](../public/com/highcapable/yukihookapi/hook/log/YLog#inmemorydata-field), [YLog.contents](../public/com/highcapable/yukihookapi/hook/log/YLog#contents-field), [YLog.contents](../public/com/highcapable/yukihookapi/hook/log/YLog#contents-method), [YLog.saveToFile](../public/com/highcapable/yukihookapi/hook/log/YLog#savetofile-method) methods and [YLog.Configs](../public/com/highcapable/yukihookapi/hook/log/YLog#configs-object).
:::

View File

@@ -4,26 +4,26 @@
## 普通日志
你可以调用 `loggerD``loggerI``loggerW` 来向控制台打印普通日志。
你可以调用 `YLog.debug``YLog.info``YLog.warn` 来向控制台打印普通日志。
使用方法如下所示。
> 示例如下
```kotlin
loggerD(msg = "This is a log")
YLog.debug(msg = "This is a log")
```
此时,`YukiHookAPI` 会调用 `android.util.Log` 与 (Xposed) 宿主环境中的日志功能同时打印这条日志。
日志默认的 `TAG` 为你在 `YukiHookLogger.Configs.tag` 中设置的值。
日志默认的 `TAG` 为你在 `YLog.Configs.tag` 中设置的值。
你也可以动态自定义这个值,但是不建议轻易修改 `TAG` 防止过滤不到日志。
> 示例如下
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log")
YLog.debug(tag = "YukiHookAPI", msg = "This is a log")
```
打印的结果为如下所示。
@@ -31,19 +31,19 @@ loggerD(tag = "YukiHookAPI", msg = "This is a log")
> 示例如下
```:no-line-numbers
[YukiHookAPI][D][宿主包名]--> This is a log
[YukiHookAPI][D][宿主包名] This is a log
```
你还可以使用 `LoggerType` 自定义日志打印的类型,可选择使用 `android.util.Log` 还是 (Xposed) 宿主环境中的日志功能来打印日志。
你还可以使用 `YLog.EnvType` 自定义日志打印的环境,可选择使用 `android.util.Log` 还是 (Xposed) 宿主环境中的日志功能来打印日志。
默认类型为 `LoggerType.BOTH`,含义为同时使用这两个方法来打印日志。
默认类型为 `YLog.EnvType.BOTH`,含义为同时使用这两个方法来打印日志。
比如我们仅使用 `android.util.Log` 来打印日志。
> 示例如下
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.LOGD)
YLog.debug(tag = "YukiHookAPI", msg = "This is a log", env = YLog.EnvType.LOGD)
```
或仅使用 (Xposed) 宿主环境中的日志功能来打印日志,此方法仅可在 (Xposed) 宿主环境使用。
@@ -51,7 +51,7 @@ loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.LOGD)
> 示例如下
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.XPOSED_ENVIRONMENT)
YLog.debug(tag = "YukiHookAPI", msg = "This is a log", env = YLog.EnvType.XPOSED_ENVIRONMENT)
```
若你想智能区分 (Xposed) 宿主环境与模块环境,可以写为如下形式。
@@ -59,27 +59,27 @@ loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.XPOSED_ENV
> 示例如下
```kotlin
loggerD(tag = "YukiHookAPI", msg = "This is a log", type = LoggerType.SCOPE)
YLog.debug(tag = "YukiHookAPI", msg = "This is a log", env = YLog.EnvType.SCOPE)
```
这样 API 就会在不同环境智能选择指定的方法类型去打印这条日志。
::: tip
更多功能请参考 [loggerD](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggerd-method)、[loggerI](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggeri-method) 及 [loggerW](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggerw-method) 方法。
更多功能请参考 [YLog.debug](../public/com/highcapable/yukihookapi/hook/log/YLog#debug-method)、[YLog.info](../public/com/highcapable/yukihookapi/hook/log/YLog#info-method) 及 [YLog.warn](../public/com/highcapable/yukihookapi/hook/log/YLog#warn-method) 方法。
:::
## 错误日志
你可以调用 `loggerE` 来向控制台打印 `E` 级别的日志。
你可以调用 `YLog.error` 来向控制台打印 `E` 级别的日志。
使用方法如下所示。
> 示例如下
```kotlin
loggerE(msg = "This is an error")
YLog.error(msg = "This is an error")
```
错误日志的级别是最高的,无论你有没有过滤仅为 `E` 级别的日志。
@@ -90,7 +90,7 @@ loggerE(msg = "This is an error")
// 假设这就是被抛出的异常
val throwable = Throwable(...)
// 打印日志
loggerE(msg = "This is an error", e = throwable)
YLog.error(msg = "This is an error", e = throwable)
```
打印的结果为如下所示。
@@ -98,7 +98,7 @@ loggerE(msg = "This is an error", e = throwable)
> 示例如下
```:no-line-numbers
[YukiHookAPI][E][宿主包名]--> This is an error
[YukiHookAPI][E][宿主包名] This is an error
```
同时,日志会帮你打印整个异常堆栈。
@@ -107,49 +107,49 @@ loggerE(msg = "This is an error", e = throwable)
```:no-line-numbers
java.lang.Throwable
at com.demo.Test.<init>(...)
at com.demo.Test.doTask(...)
at com.demo.Test.stop(...)
at com.demo.Test.init(...)
at a.a.a(...)
... 3 more
at com.demo.Test.<init>(...)
at com.demo.Test.doTask(...)
at com.demo.Test.stop(...)
at com.demo.Test.init(...)
at a.a.a(...)
... 3 more
```
在错误日志中,你同样也可以使用 `LoggerType` 来指定当前打印日志所用到的方法类型。
在错误日志中,你同样也可以使用 `YLog.EnvType` 来指定当前打印日志所用到的方法类型。
::: tip
更多功能请参考 [loggerE](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#loggere-method) 方法。
更多功能请参考 [YLog.error](../public/com/highcapable/yukihookapi/hook/log/YLog#error-method) 方法。
:::
## 保存日志与自定义元素
你可以使用 `YukiHookLogger.saveToFile` 方法直接保存当前已打印的全部日志到文件。
你可以使用 `YLog.saveToFile` 方法直接保存当前已打印的全部日志到文件。
> 示例如下
```kotlin
// 请注意保存的文件路径必须拥有读写权限,否则会抛出异常
YukiHookLogger.saveToFile("/sdcard/Documents/debug_log.log")
YLog.saveToFile("/sdcard/Documents/debug_log.log")
```
你还可以使用 `YukiHookLogger.contents` 获取当前已打印的全部日志文件内容。
你还可以使用 `YLog.contents` 获取当前已打印的全部日志文件内容。
> 示例如下
```kotlin
// 获取当前已打印的全部日志文件内容
val fileContent = YukiHookLogger.contents
val fileContent = YLog.contents
```
如果你需要一个实时日志的数据结构数组,你可以直接获取 `YukiHookLogger.inMemoryData` 的内容。
如果你需要一个实时日志的数据结构数组,你可以直接获取 `YLog.inMemoryData` 的内容。
> 示例如下
```kotlin
// 获取当前已打印的实时日志数据结构数组
YukiHookLogger.inMemoryData.forEach {
YLog.inMemoryData.forEach {
it.timestamp // 获取时间戳
it.time // 获取 UTC 时间
it.priority // 获取优先级
@@ -165,17 +165,17 @@ YukiHookLogger.inMemoryData.forEach {
```kotlin
// 假设这就是你得到的自定义日志数据
val data: ArrayList<YukiLoggerData>
val data: List<YLogData>
// 格式化日志数据到字符串
val dataString = YukiHookLogger.contents(data)
val dataString = YLog.contents(data)
// 保存日志数据到文件
// 请注意保存的文件路径必须拥有读写权限,否则会抛出异常
YukiHookLogger.saveToFile("/sdcard/Documents/debug_log.log", data)
YLog.saveToFile("/sdcard/Documents/debug_log.log", data)
```
::: danger
你需要启用 **YukiHookLogger.Configs.isRecord** 才能获取到 **YukiHookLogger.inMemoryData** 的内容。
你需要启用 **YLog.Configs.isRecord** 才能获取到 **YLog.inMemoryData** 的内容。
获取到的日志数据在 Hook APP (宿主) 及模块进程中是相互隔离的。
@@ -185,7 +185,7 @@ YukiHookLogger.saveToFile("/sdcard/Documents/debug_log.log", data)
:::
你还可以使用 `YukiHookLogger.Configs.elements` 自定义调试日志对外显示的元素。
你还可以使用 `YLog.Configs.elements` 自定义调试日志对外显示的元素。
此功能需要在 Hook 入口类的 `onInit` 中对 `YukiHookAPI.Configs` 进行配置。
@@ -203,6 +203,6 @@ override fun onInit() = configs {
::: tip
更多功能请参考 [YukiHookLogger.inMemoryData](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#inmemorydata-field)、[YukiHookLogger.contents](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#contents-field)、[YukiHookLogger.contents](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#contents-method)、[YukiHookLogger.saveToFile](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#savetofile-method) 方法以及 [YukiHookLogger.Configs](../public/com/highcapable/yukihookapi/hook/log/LoggerFactory#configs-object)。
更多功能请参考 [YLog.inMemoryData](../public/com/highcapable/yukihookapi/hook/log/YLog#inmemorydata-field)、[YLog.contents](../public/com/highcapable/yukihookapi/hook/log/YLog#contents-field)、[YLog.contents](../public/com/highcapable/yukihookapi/hook/log/YLog#contents-method)、[YLog.saveToFile](../public/com/highcapable/yukihookapi/hook/log/YLog#savetofile-method) 方法以及 [YLog.Configs](../public/com/highcapable/yukihookapi/hook/log/YLog#configs-object)。
:::