commit d147dc5ce0a92cc803ec7cc6ffbeb5091bc10144
parent 4b926f199c9af38227a5e2123774b8d5b020b766
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Sun, 12 Nov 2023 23:28:30 +0100

feat: anonymize logs

Diffstat:
Mapp/src/main/kotlin/me/rhunk/snapenhance/LogManager.kt | 14++++++++++++--
Mcommon/src/main/assets/lang/en_US.json | 4++++
Mcommon/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Scripting.kt | 1+
3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/LogManager.kt b/app/src/main/kotlin/me/rhunk/snapenhance/LogManager.kt @@ -1,6 +1,5 @@ package me.rhunk.snapenhance -import android.content.SharedPreferences import android.util.Log import com.google.gson.GsonBuilder import me.rhunk.snapenhance.common.logger.AbstractLogger @@ -108,6 +107,8 @@ class LogManager( private val LOG_LIFETIME = 24.hours } + private val anonymizeLogs by lazy { !remoteSideContext.config.root.scripting.disableLogAnonymization.get() } + var lineAddListener = { _: LogLine -> } private val logFolder = File(remoteSideContext.androidContext.cacheDir, "logs") @@ -201,7 +202,16 @@ class LogManager( fun internalLog(tag: String, logLevel: LogLevel, message: Any?) { runCatching { - val line = LogLine(logLevel, getCurrentDateTime(), tag, message.toString()) + val line = LogLine( + logLevel = logLevel, + dateTime = getCurrentDateTime(), + tag = tag, + message = message.toString().let { + if (anonymizeLogs) + it.replace(Regex("[0-9a-f]{8}-[0-9a-f]{4}-{3}[0-9a-f]{12}", RegexOption.MULTILINE), "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") + else it + } + ) logFile.appendText("|$line\n", Charsets.UTF_8) lineAddListener(line) Log.println(logLevel.priority, tag, message.toString()) diff --git a/common/src/main/assets/lang/en_US.json b/common/src/main/assets/lang/en_US.json @@ -619,6 +619,10 @@ "hot_reload": { "name": "Hot Reload", "description": "Automatically reloads scripts when they change" + }, + "disable_log_anonymization": { + "name": "Disable Log Anonymization", + "description": "Disables the anonymization of logs" } } } diff --git a/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Scripting.kt b/common/src/main/kotlin/me/rhunk/snapenhance/common/config/impl/Scripting.kt @@ -7,4 +7,5 @@ class Scripting : ConfigContainer() { val developerMode = boolean("developer_mode", false) { requireRestart() } val moduleFolder = string("module_folder", "modules") { addFlags(ConfigFlag.FOLDER); requireRestart() } val hotReload = boolean("hot_reload", false) + val disableLogAnonymization = boolean("disable_log_anonymization", false) { requireRestart() } } \ No newline at end of file