Skip to content

Commit 6b08287

Browse files
committed
refactor: allow any incoming to log in YLog
1 parent 311926b commit 6b08287

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

docs-source/src/en/config/move-to-api-1-3-x.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ Now this method will be useless and will not be called back. If necessary, pleas
9191

9292
`YukiHookAPI` Starting with `1.3.0`, the way in which the module `Activity` behavior has changed.
9393

94-
Please read [Register Module App's Activity](../api/special-features/host-inject#register-module-app-s-activity) for more information.
94+
Please read [Register Module App's Activity](../api/special-features/host-inject#register-module-app-s-activity) for more information.
95+
96+
## YLog Behavior Change
97+
98+
`YukiHookAPI` allows the `msg` parameter of `YLog` to be passed into any object starting from `1.3.0`, and they will be automatically converted using the `toString()` method.

docs-source/src/zh-cn/config/move-to-api-1-3-x.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,8 @@ val instance: Any
8585

8686
`YukiHookAPI``1.3.0` 版本开始,注册模块 `Activity` 行为的方式发生了变更。
8787

88-
请阅读 [注册模块 Activity](../api/special-features/host-inject#注册模块-activity) 以了解更多信息。
88+
请阅读 [注册模块 Activity](../api/special-features/host-inject#注册模块-activity) 以了解更多信息。
89+
90+
## YLog 行为变更
91+
92+
`YukiHookAPI``1.3.0` 版本开始允许 `YLog``msg` 参数传入任意对象,它们都会自动使用 `toString()` 方法进行转换。

yukihookapi-core/src/main/java/com/highcapable/yukihookapi/hook/log/YLog.kt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ object YLog {
231231
* @param tag 日志打印的标签 - 建议和自己的模块名称设置成一样的 - 默认为 [Configs.tag]
232232
* @param env 日志打印的环境 - 默认为 [EnvType.BOTH]
233233
*/
234-
fun debug(msg: String = "", e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
235-
log(env, YLogData(priority = "D", tag = tag, msg = msg, throwable = e))
234+
fun debug(msg: Any? = null, e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
235+
log(env, YLogData(priority = "D", tag = tag, msg = msg.toString(), throwable = e))
236236

237237
/**
238238
* 打印 Info 级别 Log
@@ -243,8 +243,8 @@ object YLog {
243243
* @param tag 日志打印的标签 - 建议和自己的模块名称设置成一样的 - 默认为 [Configs.tag]
244244
* @param env 日志打印的环境 - 默认为 [EnvType.BOTH]
245245
*/
246-
fun info(msg: String = "", e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
247-
log(env, YLogData(priority = "I", tag = tag, msg = msg, throwable = e))
246+
fun info(msg: Any? = null, e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
247+
log(env, YLogData(priority = "I", tag = tag, msg = msg.toString(), throwable = e))
248248

249249
/**
250250
* 打印 Warn 级别 Log
@@ -255,8 +255,8 @@ object YLog {
255255
* @param tag 日志打印的标签 - 建议和自己的模块名称设置成一样的 - 默认为 [Configs.tag]
256256
* @param env 日志打印的环境 - 默认为 [EnvType.BOTH]
257257
*/
258-
fun warn(msg: String = "", e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
259-
log(env, YLogData(priority = "W", tag = tag, msg = msg, throwable = e))
258+
fun warn(msg: Any? = null, e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
259+
log(env, YLogData(priority = "W", tag = tag, msg = msg.toString(), throwable = e))
260260

261261
/**
262262
* 打印 Error 级别 Log
@@ -267,18 +267,18 @@ object YLog {
267267
* @param e 可填入异常堆栈信息 - 将自动完整打印到控制台
268268
* @param env 日志打印的环境 - 默认为 [EnvType.BOTH]
269269
*/
270-
fun error(msg: String = "", e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
271-
log(env, YLogData(priority = "E", tag = tag, msg = msg, throwable = e))
270+
fun error(msg: Any? = null, e: Throwable? = null, tag: String = Configs.tag, env: EnvType = EnvType.BOTH) =
271+
log(env, YLogData(priority = "E", tag = tag, msg = msg.toString(), throwable = e))
272272

273273
/**
274274
* [YukiHookAPI] (内部) 打印 Debug 级别 Log
275275
* @param msg 日志打印的内容 - 默认空 - 如果你仅想打印异常堆栈可只设置 [e]
276276
* @param e 可填入异常堆栈信息 - 将自动完整打印到控制台
277277
* @param isImplicit 是否隐式打印 - 不会记录 - 也不会显示包名和用户 ID
278278
*/
279-
internal fun innerD(msg: String = "", e: Throwable? = null, isImplicit: Boolean = false) {
279+
internal fun innerD(msg: Any? = null, e: Throwable? = null, isImplicit: Boolean = false) {
280280
if (Configs.isEnable.not() || YukiHookAPI.Configs.isDebug.not()) return initKavaRefLoggerIfNot()
281-
log(EnvType.BOTH, YLogData(priority = "D", msg = msg, throwable = e), isImplicit)
281+
log(EnvType.BOTH, YLogData(priority = "D", msg = msg.toString(), throwable = e), isImplicit)
282282
}
283283

284284
/**
@@ -287,9 +287,9 @@ object YLog {
287287
* @param e 可填入异常堆栈信息 - 将自动完整打印到控制台
288288
* @param isImplicit 是否隐式打印 - 不会记录 - 也不会显示包名和用户 ID
289289
*/
290-
internal fun innerI(msg: String = "", e: Throwable? = null, isImplicit: Boolean = false) {
290+
internal fun innerI(msg: Any? = null, e: Throwable? = null, isImplicit: Boolean = false) {
291291
if (Configs.isEnable.not()) return initKavaRefLoggerIfNot()
292-
log(EnvType.BOTH, YLogData(priority = "I", msg = msg, throwable = e), isImplicit)
292+
log(EnvType.BOTH, YLogData(priority = "I", msg = msg.toString(), throwable = e), isImplicit)
293293
}
294294

295295
/**
@@ -298,9 +298,9 @@ object YLog {
298298
* @param e 可填入异常堆栈信息 - 将自动完整打印到控制台
299299
* @param isImplicit 是否隐式打印 - 不会记录 - 也不会显示包名和用户 ID
300300
*/
301-
internal fun innerW(msg: String = "", e: Throwable? = null, isImplicit: Boolean = false) {
301+
internal fun innerW(msg: Any? = null, e: Throwable? = null, isImplicit: Boolean = false) {
302302
if (Configs.isEnable.not()) return initKavaRefLoggerIfNot()
303-
log(EnvType.BOTH, YLogData(priority = "W", msg = msg, throwable = e), isImplicit)
303+
log(EnvType.BOTH, YLogData(priority = "W", msg = msg.toString(), throwable = e), isImplicit)
304304
}
305305

306306
/**
@@ -309,9 +309,9 @@ object YLog {
309309
* @param e 可填入异常堆栈信息 - 将自动完整打印到控制台
310310
* @param isImplicit 是否隐式打印 - 不会记录 - 也不会显示包名和用户 ID
311311
*/
312-
internal fun innerE(msg: String = "", e: Throwable? = null, isImplicit: Boolean = false) {
312+
internal fun innerE(msg: Any? = null, e: Throwable? = null, isImplicit: Boolean = false) {
313313
if (Configs.isEnable.not()) return initKavaRefLoggerIfNot()
314-
log(EnvType.BOTH, YLogData(priority = "E", msg = msg, throwable = e), isImplicit)
314+
log(EnvType.BOTH, YLogData(priority = "E", msg = msg.toString(), throwable = e), isImplicit)
315315
}
316316

317317
/**

0 commit comments

Comments
 (0)