Added|Changed: Add Logger.logErrorPrivate*() functions which do not log errors that may contain potentially private info unless log level is debug or higher

Execution commands and other errors that may contain potentially private info should not be logged unless user has explicitly allowed it since apps with `READ_LOGS` permission would be able to read the data. A notification for failed executions commands would still be shown if enabled and required.
This commit is contained in:
agnostic-apollo
2022-04-17 06:30:17 +05:00
parent 89a08ff01a
commit 6bda7c4fc4
3 changed files with 34 additions and 6 deletions

View File

@@ -455,8 +455,10 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
// If the execution command was started for a plugin, then process the error
if (executionCommand.isPluginExecutionCommand)
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else
Logger.logErrorExtended(LOG_TAG, executionCommand.toString());
else {
Logger.logError(LOG_TAG, "Set log level to debug or higher to see error in logs");
Logger.logErrorPrivateExtended(LOG_TAG, executionCommand.toString());
}
return null;
}
@@ -576,8 +578,10 @@ public final class TermuxService extends Service implements AppShell.AppShellCli
// If the execution command was started for a plugin, then process the error
if (executionCommand.isPluginExecutionCommand)
TermuxPluginUtils.processPluginExecutionCommandError(this, LOG_TAG, executionCommand, false);
else
Logger.logErrorExtended(LOG_TAG, executionCommand.toString());
else {
Logger.logError(LOG_TAG, "Set log level to debug or higher to see error in logs");
Logger.logErrorPrivateExtended(LOG_TAG, executionCommand.toString());
}
return null;
}

View File

@@ -120,6 +120,28 @@ public class Logger {
public static void logErrorPrivate(String tag, String message) {
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG)
logMessage(Log.ERROR, tag, message);
}
public static void logErrorPrivate(String message) {
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG)
logMessage(Log.ERROR, DEFAULT_LOG_TAG, message);
}
public static void logErrorPrivateExtended(String tag, String message) {
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG)
logExtendedMessage(Log.ERROR, tag, message);
}
public static void logErrorPrivateExtended(String message) {
if (CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG)
logExtendedMessage(Log.ERROR, DEFAULT_LOG_TAG, message);
}
public static void logWarn(String tag, String message) {
logMessage(Log.WARN, tag, message);
}

View File

@@ -144,7 +144,9 @@ public class TermuxPluginUtils {
boolean isExecutionCommandLoggingEnabled = Logger.shouldEnableLoggingForCustomLogLevel(executionCommand.backgroundCustomLogLevel);
// Log the error and any exception. ResultData should not be logged if pending result since ResultSender will do it
Logger.logErrorExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true,
Logger.logError(logTag, "Processing plugin execution error for:\n" + executionCommand.getCommandIdAndLabelLogString());
Logger.logError(logTag, "Set log level to debug or higher to see error in logs");
Logger.logErrorPrivateExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true,
!isPluginExecutionCommandWithPendingResult, isExecutionCommandLoggingEnabled));
// If execution command was started by a plugin which expects the result back
@@ -161,7 +163,7 @@ public class TermuxPluginUtils {
if (error != null) {
// error will be added to existing Errors
resultData.setStateFailed(error);
Logger.logErrorExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true, true, isExecutionCommandLoggingEnabled));
Logger.logErrorPrivateExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true, true, isExecutionCommandLoggingEnabled));
forceNotification = true;
}