refactor: merge logs related function to debugLog and YLog.Configs

This commit is contained in:
2023-09-27 21:41:15 +08:00
parent 3a0c8cfef6
commit bb9c38cde9
9 changed files with 64 additions and 44 deletions

View File

@@ -25,12 +25,13 @@
* *
* This file is created by fankes on 2023/1/21. * This file is created by fankes on 2023/1/21.
*/ */
@file:Suppress("unused") @file:Suppress("unused", "MemberVisibilityCanBePrivate", "NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
package com.highcapable.yukireflection package com.highcapable.yukireflection
import com.highcapable.yukireflection.YukiReflection.Configs import com.highcapable.yukireflection.YukiReflection.Configs
import com.highcapable.yukireflection.generated.YukiReflectionProperties import com.highcapable.yukireflection.generated.YukiReflectionProperties
import com.highcapable.yukireflection.log.YLog
import java.lang.reflect.Member import java.lang.reflect.Member
/** /**
@@ -71,14 +72,24 @@ object YukiReflection {
*/ */
object Configs { object Configs {
/**
* 配置 [YLog.Configs] 相关参数
* @param initiate 方法体
*/
inline fun debugLog(initiate: YLog.Configs.() -> Unit) = YLog.Configs.apply(initiate).build()
/** /**
* 这是一个调试日志的全局标识 * 这是一个调试日志的全局标识
* *
* 默认文案为 [TAG] * - 此方法已弃用 - 在之后的版本中将直接被删除
* *
* 你可以修改为你自己的文案 * - 请现在迁移到 [debugLog] 并使用 [YLog.Configs.tag]
*/ */
var debugTag = TAG @Deprecated(message = "请使用新方式来实现此功能")
var debugTag get() = YLog.Configs.tag
set(value) {
YLog.Configs.tag = value
}
/** /**
* 是否开启调试模式 - 默认不启用 * 是否开启调试模式 - 默认不启用
@@ -89,24 +100,17 @@ object YukiReflection {
*/ */
var isDebug = false var isDebug = false
/**
* 是否启用调试日志的输出功能
*
* - 关闭后将会停用 [YukiReflection] 对全部日志的输出 - 同时 [isDebug] 将不再有效
*/
var isEnableLogs = true
/** /**
* 是否启用调试日志的输出功能 * 是否启用调试日志的输出功能
* *
* - 此方法已弃用 - 在之后的版本中将直接被删除 * - 此方法已弃用 - 在之后的版本中将直接被删除
* *
* - 请现在迁移到 [isEnableLogs] * - 请现在迁移到 [debugLog] 并使用 [YLog.Configs.isEnable]
*/ */
@Deprecated(message = "请使用新方式来实现此功能", ReplaceWith("isEnableLogs")) @Deprecated(message = "请使用新方式来实现此功能")
var isAllowPrintingLogs get() = isEnableLogs var isAllowPrintingLogs get() = YLog.Configs.isEnable
set(value) { set(value) {
isEnableLogs = value YLog.Configs.isEnable = value
} }
/** /**
@@ -118,13 +122,14 @@ object YukiReflection {
*/ */
@Deprecated(message = "此方法及功能已被移除,请删除此方法") @Deprecated(message = "此方法及功能已被移除,请删除此方法")
var isEnableMemberCache = false var isEnableMemberCache = false
/** 结束方法体 */
internal fun build() = Unit
} }
/** /**
* 配置 [YukiReflection] 相关参数 * 配置 [YukiReflection] 相关参数
* @param initiate 方法体 * @param initiate 方法体
*/ */
inline fun configs(initiate: Configs.() -> Unit) { inline fun configs(initiate: Configs.() -> Unit) = Configs.apply(initiate).build()
Configs.apply(initiate)
}
} }

View File

@@ -29,7 +29,7 @@
package com.highcapable.yukireflection.finder.base package com.highcapable.yukireflection.finder.base
import com.highcapable.yukireflection.YukiReflection import com.highcapable.yukireflection.YukiReflection
import com.highcapable.yukireflection.utils.debug.YLog import com.highcapable.yukireflection.log.YLog
/** /**
* 这是 [Class] 查找类功能的基本类实现 * 这是 [Class] 查找类功能的基本类实现

View File

@@ -31,7 +31,7 @@
package com.highcapable.yukireflection.finder.base package com.highcapable.yukireflection.finder.base
import com.highcapable.yukireflection.YukiReflection import com.highcapable.yukireflection.YukiReflection
import com.highcapable.yukireflection.utils.debug.YLog import com.highcapable.yukireflection.log.YLog
import com.highcapable.yukireflection.utils.factory.await import com.highcapable.yukireflection.utils.factory.await
import java.lang.reflect.Constructor import java.lang.reflect.Constructor
import java.lang.reflect.Field import java.lang.reflect.Field

View File

@@ -47,7 +47,7 @@ import com.highcapable.yukireflection.finder.classes.rules.result.MemberRulesRes
import com.highcapable.yukireflection.finder.tools.ReflectionTool import com.highcapable.yukireflection.finder.tools.ReflectionTool
import com.highcapable.yukireflection.finder.type.factory.ModifierConditions import com.highcapable.yukireflection.finder.type.factory.ModifierConditions
import com.highcapable.yukireflection.finder.type.factory.NameConditions import com.highcapable.yukireflection.finder.type.factory.NameConditions
import com.highcapable.yukireflection.utils.debug.YLog import com.highcapable.yukireflection.log.YLog
import com.highcapable.yukireflection.utils.factory.await import com.highcapable.yukireflection.utils.factory.await
import com.highcapable.yukireflection.utils.factory.runBlocking import com.highcapable.yukireflection.utils.factory.runBlocking
import dalvik.system.BaseDexClassLoader import dalvik.system.BaseDexClassLoader

View File

@@ -42,7 +42,7 @@ import com.highcapable.yukireflection.finder.type.factory.ModifierConditions
import com.highcapable.yukireflection.finder.type.factory.ObjectsConditions import com.highcapable.yukireflection.finder.type.factory.ObjectsConditions
import com.highcapable.yukireflection.type.defined.UndefinedType import com.highcapable.yukireflection.type.defined.UndefinedType
import com.highcapable.yukireflection.type.defined.VagueType import com.highcapable.yukireflection.type.defined.VagueType
import com.highcapable.yukireflection.utils.debug.YLog import com.highcapable.yukireflection.log.YLog
import com.highcapable.yukireflection.utils.factory.runBlocking import com.highcapable.yukireflection.utils.factory.runBlocking
import java.lang.reflect.Constructor import java.lang.reflect.Constructor

View File

@@ -42,7 +42,7 @@ import com.highcapable.yukireflection.finder.type.factory.FieldConditions
import com.highcapable.yukireflection.finder.type.factory.ModifierConditions import com.highcapable.yukireflection.finder.type.factory.ModifierConditions
import com.highcapable.yukireflection.finder.type.factory.NameConditions import com.highcapable.yukireflection.finder.type.factory.NameConditions
import com.highcapable.yukireflection.finder.type.factory.ObjectConditions import com.highcapable.yukireflection.finder.type.factory.ObjectConditions
import com.highcapable.yukireflection.utils.debug.YLog import com.highcapable.yukireflection.log.YLog
import com.highcapable.yukireflection.utils.factory.runBlocking import com.highcapable.yukireflection.utils.factory.runBlocking
import java.lang.reflect.Field import java.lang.reflect.Field

View File

@@ -44,7 +44,7 @@ import com.highcapable.yukireflection.finder.type.factory.ObjectConditions
import com.highcapable.yukireflection.finder.type.factory.ObjectsConditions import com.highcapable.yukireflection.finder.type.factory.ObjectsConditions
import com.highcapable.yukireflection.type.defined.UndefinedType import com.highcapable.yukireflection.type.defined.UndefinedType
import com.highcapable.yukireflection.type.defined.VagueType import com.highcapable.yukireflection.type.defined.VagueType
import com.highcapable.yukireflection.utils.debug.YLog import com.highcapable.yukireflection.log.YLog
import com.highcapable.yukireflection.utils.factory.runBlocking import com.highcapable.yukireflection.utils.factory.runBlocking
import java.lang.reflect.Method import java.lang.reflect.Method

View File

@@ -49,7 +49,7 @@ import com.highcapable.yukireflection.type.java.DalvikBaseDexClassLoader
import com.highcapable.yukireflection.type.java.NoClassDefFoundErrorClass import com.highcapable.yukireflection.type.java.NoClassDefFoundErrorClass
import com.highcapable.yukireflection.type.java.NoSuchFieldErrorClass import com.highcapable.yukireflection.type.java.NoSuchFieldErrorClass
import com.highcapable.yukireflection.type.java.NoSuchMethodErrorClass import com.highcapable.yukireflection.type.java.NoSuchMethodErrorClass
import com.highcapable.yukireflection.utils.debug.YLog import com.highcapable.yukireflection.log.YLog
import com.highcapable.yukireflection.utils.factory.conditions import com.highcapable.yukireflection.utils.factory.conditions
import com.highcapable.yukireflection.utils.factory.findLastIndex import com.highcapable.yukireflection.utils.factory.findLastIndex
import com.highcapable.yukireflection.utils.factory.lastIndex import com.highcapable.yukireflection.utils.factory.lastIndex

View File

@@ -27,7 +27,7 @@
*/ */
@file:Suppress("unused") @file:Suppress("unused")
package com.highcapable.yukireflection.utils.debug package com.highcapable.yukireflection.log
import android.util.Log import android.util.Log
import com.highcapable.yukireflection.YukiReflection import com.highcapable.yukireflection.YukiReflection
@@ -37,19 +37,34 @@ import com.highcapable.yukireflection.utils.factory.dumpToString
/** /**
* 全局 Log 管理类 * 全局 Log 管理类
*/ */
internal object YLog { object YLog {
/** /**
* 是否启用 * 配置 [YLog]
* @return [Boolean]
*/ */
private val isEnable get() = YukiReflection.Configs.isEnableLogs object Configs {
/** /**
* Log 标签 * 这是一个调试日志的全局标识
* @return [String] *
*/ * 默认文案为 [YukiReflection.TAG]
private val tag get() = YukiReflection.Configs.debugTag *
* 你可以修改为你自己的文案
*/
var tag = YukiReflection.TAG
/**
* 是否启用调试日志的输出功能 - 默认启用
*
* - 关闭后将会停用 [YukiReflection] 对全部日志的输出
*
* [isEnable] 关闭后 [YukiReflection.Configs.isDebug] 也将同时关闭
*/
var isEnable = true
/** 结束方法体 */
internal fun build() = Unit
}
/** /**
* 打印 Debug 级别 Log * 打印 Debug 级别 Log
@@ -57,7 +72,7 @@ internal object YLog {
* @param e 异常堆栈 - 默认空 * @param e 异常堆栈 - 默认空
*/ */
internal fun debug(msg: String, e: Throwable? = null) { internal fun debug(msg: String, e: Throwable? = null) {
if (isEnable) log(Type.DEBUG, msg, e) if (Configs.isEnable) log(Type.DEBUG, msg, e)
} }
/** /**
@@ -66,7 +81,7 @@ internal object YLog {
* @param e 异常堆栈 - 默认空 * @param e 异常堆栈 - 默认空
*/ */
internal fun info(msg: String, e: Throwable? = null) { internal fun info(msg: String, e: Throwable? = null) {
if (isEnable) log(Type.INFO, msg, e) if (Configs.isEnable) log(Type.INFO, msg, e)
} }
/** /**
@@ -75,7 +90,7 @@ internal object YLog {
* @param e 异常堆栈 - 默认空 * @param e 异常堆栈 - 默认空
*/ */
internal fun warn(msg: String, e: Throwable? = null) { internal fun warn(msg: String, e: Throwable? = null) {
if (isEnable) log(Type.WARN, msg, e) if (Configs.isEnable) log(Type.WARN, msg, e)
} }
/** /**
@@ -84,7 +99,7 @@ internal object YLog {
* @param e 异常堆栈 - 默认空 * @param e 异常堆栈 - 默认空
*/ */
internal fun error(msg: String, e: Throwable? = null) { internal fun error(msg: String, e: Throwable? = null) {
if (isEnable) log(Type.ERROR, msg, e) if (Configs.isEnable) log(Type.ERROR, msg, e)
} }
/** /**
@@ -95,7 +110,7 @@ internal object YLog {
*/ */
private fun log(type: Type, msg: String, e: Throwable? = null) { private fun log(type: Type, msg: String, e: Throwable? = null) {
val isAndroid = "android.util.Log".hasClass() val isAndroid = "android.util.Log".hasClass()
val mixedContent = "[$tag][${type.alias}] $msg" val mixedContent = "[${Configs.tag}][${type.alias}] $msg"
/** /**
* 打印 Log * 打印 Log
@@ -104,10 +119,10 @@ internal object YLog {
fun innerLog(msg: String) { fun innerLog(msg: String) {
when { when {
isAndroid -> when (type) { isAndroid -> when (type) {
Type.DEBUG -> Log.d(tag, msg, e) Type.DEBUG -> Log.d(Configs.tag, msg, e)
Type.INFO -> Log.i(tag, msg, e) Type.INFO -> Log.i(Configs.tag, msg, e)
Type.WARN -> Log.w(tag, msg, e) Type.WARN -> Log.w(Configs.tag, msg, e)
Type.ERROR -> Log.e(tag, msg, e) Type.ERROR -> Log.e(Configs.tag, msg, e)
} }
type.color.isBlank() -> println(mixedContent) type.color.isBlank() -> println(mixedContent)
else -> println("\u001B[${type.color}m$mixedContent\u001B[0m") else -> println("\u001B[${type.color}m$mixedContent\u001B[0m")