Optimize and improve log

Use Log.e() instead of e.printStackTrace()
This commit is contained in:
2dust
2025-03-30 17:40:36 +08:00
parent 45facff41d
commit 6cc91b1a89
37 changed files with 172 additions and 152 deletions
@@ -42,7 +42,7 @@ object AngConfigManager {
Utils.setClipboard(context, conf)
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to share config to clipboard", e)
return -1
}
return 0
@@ -71,7 +71,7 @@ object AngConfigManager {
}
return sb.lines().count()
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to share non-custom configs to clipboard", e)
return -1
}
}
@@ -91,7 +91,7 @@ object AngConfigManager {
return QRCodeDecoder.createQRCode(conf)
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to share config as QR code", e)
return null
}
}
@@ -120,7 +120,7 @@ object AngConfigManager {
return -1
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to share full content to clipboard", e)
return -1
}
return 0
@@ -148,7 +148,7 @@ object AngConfigManager {
EConfigType.HYSTERIA2 -> Hysteria2Fmt.toUri(config)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to share config for GUID: $guid", e)
return ""
}
}
@@ -203,7 +203,7 @@ object AngConfigManager {
}
return count
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to parse batch subscription", e)
}
return 0
}
@@ -251,7 +251,7 @@ object AngConfigManager {
}
return count
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to parse batch config", e)
}
return 0
}
@@ -287,7 +287,7 @@ object AngConfigManager {
return count
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to parse custom config server JSON array", e)
}
try {
@@ -298,7 +298,7 @@ object AngConfigManager {
MmkvManager.encodeServerRaw(key, server)
return 1
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to parse custom config server as single config", e)
}
return 0
} else if (server.startsWith("[Interface]") && server.contains("[Peer]")) {
@@ -308,7 +308,7 @@ object AngConfigManager {
MmkvManager.encodeServerRaw(key, server)
return 1
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to parse WireGuard config file", e)
}
return 0
} else {
@@ -372,7 +372,7 @@ object AngConfigManager {
MmkvManager.setSelectServer(guid)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to parse config", e)
return -1
}
return 0
@@ -390,7 +390,7 @@ object AngConfigManager {
count += updateConfigViaSub(it)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to update config via all subscriptions", e)
return 0
}
return count
@@ -417,21 +417,20 @@ object AngConfigManager {
if (!Utils.isValidUrl(url)) {
return 0
}
Log.d(AppConfig.ANG_PACKAGE, url)
Log.d(AppConfig.TAG, url)
var configText = try {
val httpPort = SettingsManager.getHttpPort()
HttpUtil.getUrlContentWithUserAgent(url, 15000, httpPort)
} catch (e: Exception) {
Log.e(AppConfig.ANG_PACKAGE, "Update subscription: proxy not ready or other error, try……")
//e.printStackTrace()
Log.e(AppConfig.ANG_PACKAGE, "Update subscription: proxy not ready or other error, try……", e)
""
}
if (configText.isEmpty()) {
configText = try {
HttpUtil.getUrlContentWithUserAgent(url)
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to get URL content with user agent", e)
""
}
}
@@ -440,7 +439,7 @@ object AngConfigManager {
}
return parseConfigViaSub(configText, it.first, false)
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to update config via subscription", e)
return 0
}
}
@@ -3,7 +3,6 @@ package com.v2ray.ang.handler
import android.util.Log
import com.tencent.mmkv.MMKV
import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.ANG_PACKAGE
import com.v2ray.ang.dto.EConfigType
import com.v2ray.ang.dto.NetworkType
import com.v2ray.ang.dto.ProfileItem
@@ -26,7 +25,7 @@ object MigrateManager {
return false
}
val serverList = serverStorage.allKeys() ?: return false
Log.d(ANG_PACKAGE, "migrateServerConfig2Profile-" + serverList.count())
Log.d(AppConfig.TAG, "migrateServerConfig2Profile-" + serverList.count())
for (guid in serverList) {
var configOld = decodeServerConfigOld(guid) ?: continue
@@ -43,9 +42,9 @@ object MigrateManager {
//check and remove old
decodeServerConfig(guid) ?: continue
serverStorage.remove(guid)
Log.d(ANG_PACKAGE, "migrateServerConfig2Profile-" + config.remarks)
Log.d(AppConfig.TAG, "migrateServerConfig2Profile-" + config.remarks)
}
Log.d(ANG_PACKAGE, "migrateServerConfig2Profile-end")
Log.d(AppConfig.TAG, "migrateServerConfig2Profile-end")
return true
}
@@ -571,7 +571,7 @@ object MmkvManager {
* @param startOnBoot Whether to start on boot.
*/
fun encodeStartOnBoot(startOnBoot: Boolean) {
MmkvManager.encodeSettings(PREF_IS_BOOTED, startOnBoot)
encodeSettings(PREF_IS_BOOTED, startOnBoot)
}
/**
@@ -84,7 +84,7 @@ object SettingsManager {
resetRoutingRulesetsCommon(rulesetList)
return true
} catch (e: Exception) {
e.printStackTrace()
Log.e(ANG_PACKAGE, "Failed to reset routing rulesets", e)
return false
}
}
@@ -167,11 +167,11 @@ object SettingsManager {
}
val guid = MmkvManager.getSelectServer() ?: return false
val config = MmkvManager.decodeServerConfig(guid) ?: return false
val config = decodeServerConfig(guid) ?: return false
if (config.configType == EConfigType.CUSTOM) {
val raw = MmkvManager.decodeServerRaw(guid) ?: return false
val v2rayConfig = JsonUtil.fromJson(raw, V2rayConfig::class.java)
val exist = v2rayConfig.routing.rules.filter { it.outboundTag == TAG_DIRECT }?.any {
val exist = v2rayConfig.routing.rules.filter { it.outboundTag == TAG_DIRECT }.any {
it.domain?.contains(GEOSITE_PRIVATE) == true || it.ip?.contains(GEOIP_PRIVATE) == true
}
return exist == true
@@ -265,10 +265,7 @@ object SettingsManager {
input.copyTo(output)
}
}
Log.i(
ANG_PACKAGE,
"Copied from apk assets folder to ${target.absolutePath}"
)
Log.d(AppConfig.TAG, "Copied from apk assets folder to ${target.absolutePath}")
}
} catch (e: Exception) {
Log.e(ANG_PACKAGE, "asset copy failed", e)
@@ -51,7 +51,7 @@ object SpeedtestManager {
return try {
Libv2ray.measureOutboundDelay(config, SettingsManager.getDelayTestUrl())
} catch (e: Exception) {
Log.d(AppConfig.ANG_PACKAGE, "realPing: $e")
Log.d(AppConfig.TAG, "realPing: $e")
-1L
}
}
@@ -76,7 +76,7 @@ object SpeedtestManager {
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to ping URL: $url", e)
}
return "-1ms"
}
@@ -103,11 +103,11 @@ object SpeedtestManager {
socket.close()
return time
} catch (e: UnknownHostException) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Unknown host: $url", e)
} catch (e: IOException) {
Log.d(AppConfig.ANG_PACKAGE, "socketConnectTime IOException: $e")
Log.d(AppConfig.TAG, "socketConnectTime IOException: $e")
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to establish socket connection to $url:$port", e)
}
return -1
}
@@ -152,13 +152,13 @@ object SpeedtestManager {
)
}
} catch (e: IOException) {
Log.d(AppConfig.ANG_PACKAGE, "testConnection IOException: " + Log.getStackTraceString(e))
Log.d(AppConfig.TAG, "testConnection IOException: " + Log.getStackTraceString(e))
result = context.getString(R.string.connection_test_error, e.message)
} catch (e: Exception) {
Log.d(AppConfig.ANG_PACKAGE, "testConnection Exception: " + Log.getStackTraceString(e))
Log.d(AppConfig.TAG, "testConnection Exception: " + Log.getStackTraceString(e))
result = context.getString(R.string.connection_test_error, e.message)
} finally {
conn?.disconnect()
conn.disconnect()
}
return Pair(elapsed, result)
@@ -4,7 +4,6 @@ import android.content.Context
import android.text.TextUtils
import android.util.Log
import com.v2ray.ang.AppConfig
import com.v2ray.ang.AppConfig.ANG_PACKAGE
import com.v2ray.ang.AppConfig.DEFAULT_NETWORK
import com.v2ray.ang.AppConfig.DNS_ALIDNS_ADDRESSES
import com.v2ray.ang.AppConfig.DNS_ALIDNS_DOMAIN
@@ -70,7 +69,7 @@ object V2rayConfigManager {
getV2rayNormalConfig(context, guid, config)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to get V2ray config", e)
return ConfigResult(false)
}
}
@@ -91,7 +90,7 @@ object V2rayConfigManager {
getV2rayNormalConfig4Speedtest(context, guid, config)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to get V2ray config for speedtest", e)
return ConfigResult(false)
}
}
@@ -123,7 +122,7 @@ object V2rayConfigManager {
val address = config.server ?: return result
if (!Utils.isIpAddress(address)) {
if (!Utils.isValidUrl(address)) {
Log.d(ANG_PACKAGE, "$address is an invalid ip or domain")
Log.d(AppConfig.TAG, "$address is an invalid ip or domain")
return result
}
}
@@ -173,7 +172,7 @@ object V2rayConfigManager {
val address = config.server ?: return result
if (!Utils.isIpAddress(address)) {
if (!Utils.isValidUrl(address)) {
Log.d(ANG_PACKAGE, "$address is an invalid ip or domain")
Log.d(AppConfig.TAG, "$address is an invalid ip or domain")
return result
}
}
@@ -256,7 +255,7 @@ object V2rayConfigManager {
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to configure inbounds", e)
return false
}
return true
@@ -319,7 +318,7 @@ object V2rayConfigManager {
routingUserRule(key, v2rayConfig)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to configure routing", e)
return false
}
return true
@@ -336,7 +335,7 @@ object V2rayConfigManager {
v2rayConfig.routing.rules.add(rule)
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to apply routing user rule", e)
}
}
@@ -422,7 +421,7 @@ object V2rayConfigManager {
)
)
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to configure custom local DNS", e)
return false
}
return true
@@ -486,7 +485,7 @@ object V2rayConfigManager {
if (userHostsMap != null) hosts.putAll(userHostsMap)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to configure user DNS hosts", e)
}
//block dns
@@ -525,7 +524,7 @@ object V2rayConfigManager {
)
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to configure DNS", e)
return false
}
return true
@@ -596,7 +595,7 @@ object V2rayConfigManager {
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to update outbound with global settings", e)
return false
}
return true
@@ -662,7 +661,7 @@ object V2rayConfigManager {
dialerProxy = TAG_FRAGMENT
)
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to update outbound fragment", e)
return false
}
return true
@@ -725,7 +724,7 @@ object V2rayConfigManager {
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.e(AppConfig.TAG, "Failed to configure more outbounds", e)
return returnPair
}