Browse Source

[core] 默认关闭进行登录验证时的内部日志; 可使用 system prop `mirai.network.auth.logging=true` 启用

Him188 2 years ago
parent
commit
2eb313ba69

+ 1 - 0
docs/DebuggingNetwork.md

@@ -17,6 +17,7 @@
 | `mirai.network.handler.selector.logging`            | `true`/`false`                   | 启用执行重连时的详细日志                                                                           |
 | `mirai.network.handler.cancellation.trace`          | `true`/`false`                   | 让网络层的异常时包含详细原因                                                                         |
 | `mirai.network.state.observer.logging`              | `true`/`on`/`false`/`off`/`full` | 启用网络层状态变更的日志                                                                           |
+| `mirai.network.auth.logging`                        | `true`/`false`                   | 启用进行登录验证时的内部日志                                                                         |
 | `mirai.event.launch.undispatched`                   | `true`/`false`                   | 详见 [源码内注释][launch-undispatched]                                                        |
 | `mirai.resource.creation.stack.enabled`             | `true`/`false`                   | 启用 `ExternalResource` 创建时的 stacktrace 记录 (影响性能), 在资源泄露时展示                              |
 | `mirai.unknown.image.type.logging`                  | `true`/`false`                   | 启用遇到未知图片格式时的日志                                                                         |

+ 6 - 5
mirai-core/src/commonMain/kotlin/network/auth/AuthControl.kt

@@ -14,13 +14,10 @@ import net.mamoe.mirai.auth.BotAuthorization
 import net.mamoe.mirai.internal.network.components.SsoProcessorImpl
 import net.mamoe.mirai.internal.utils.asUtilsLogger
 import net.mamoe.mirai.internal.utils.subLogger
-import net.mamoe.mirai.utils.ExceptionCollector
-import net.mamoe.mirai.utils.MiraiLogger
+import net.mamoe.mirai.utils.*
 import net.mamoe.mirai.utils.channels.OnDemandChannel
 import net.mamoe.mirai.utils.channels.OnDemandReceiveChannel
 import net.mamoe.mirai.utils.channels.ProducerFailureException
-import net.mamoe.mirai.utils.debug
-import net.mamoe.mirai.utils.verbose
 import kotlin.coroutines.CoroutineContext
 
 
@@ -41,7 +38,7 @@ internal class AuthControl(
     private val userDecisions: OnDemandReceiveChannel<Throwable?, SsoProcessorImpl.AuthMethod> =
         OnDemandChannel(
             parentCoroutineContext,
-            logger.subLogger("AuthControl/UserDecisions").asUtilsLogger()
+            logger.subLogger("AuthControl/UserDecisions").withSwitch(DEBUG_LOGGING).asUtilsLogger()
         ) { _ ->
             val sessionImpl = SafeBotAuthSession(this)
             authorization.authorize(sessionImpl, botAuthInfo) // OnDemandChannel handles exceptions for us
@@ -74,4 +71,8 @@ internal class AuthControl(
         logger.verbose { "[AuthControl/resume] Fire auth completed" }
         userDecisions.close()
     }
+
+    private companion object {
+        private val DEBUG_LOGGING = systemProp("mirai.network.auth.logging", false)
+    }
 }