mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Changed!: Changes introduced to disable/change logging in 60f37bde
now also apply to stdin and plugin command results
This commit is contained in:
@@ -65,9 +65,12 @@ public class PluginUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isPluginExecutionCommandWithPendingResult = executionCommand.isPluginExecutionCommandWithPendingResult();
|
boolean isPluginExecutionCommandWithPendingResult = executionCommand.isPluginExecutionCommandWithPendingResult();
|
||||||
|
boolean isExecutionCommandLoggingEnabled = Logger.shouldEnableLoggingForCustomLogLevel(executionCommand.backgroundCustomLogLevel);
|
||||||
|
|
||||||
// Log the output. ResultData should not be logged if pending result since ResultSender will do it
|
// Log the output. ResultData should not be logged if pending result since ResultSender will do it
|
||||||
Logger.logDebugExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true, !isPluginExecutionCommandWithPendingResult));
|
// or if logging is disabled
|
||||||
|
Logger.logDebugExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true,
|
||||||
|
!isPluginExecutionCommandWithPendingResult, isExecutionCommandLoggingEnabled));
|
||||||
|
|
||||||
// If execution command was started by a plugin which expects the result back
|
// If execution command was started by a plugin which expects the result back
|
||||||
if (isPluginExecutionCommandWithPendingResult) {
|
if (isPluginExecutionCommandWithPendingResult) {
|
||||||
@@ -78,11 +81,12 @@ public class PluginUtils {
|
|||||||
setPluginResultDirectoryVariables(executionCommand);
|
setPluginResultDirectoryVariables(executionCommand);
|
||||||
|
|
||||||
// Send result to caller
|
// Send result to caller
|
||||||
error = ResultSender.sendCommandResultData(context, logTag, executionCommand.getCommandIdAndLabelLogString(), executionCommand.resultConfig, executionCommand.resultData);
|
error = ResultSender.sendCommandResultData(context, logTag, executionCommand.getCommandIdAndLabelLogString(),
|
||||||
|
executionCommand.resultConfig, executionCommand.resultData, isExecutionCommandLoggingEnabled);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
// error will be added to existing Errors
|
// error will be added to existing Errors
|
||||||
resultData.setStateFailed(error);
|
resultData.setStateFailed(error);
|
||||||
Logger.logDebugExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true, true));
|
Logger.logDebugExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true, true, isExecutionCommandLoggingEnabled));
|
||||||
|
|
||||||
// Flash and send notification for the error
|
// Flash and send notification for the error
|
||||||
Logger.showToast(context, ResultData.getErrorsListMinimalString(resultData), true);
|
Logger.showToast(context, ResultData.getErrorsListMinimalString(resultData), true);
|
||||||
@@ -133,9 +137,11 @@ public class PluginUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isPluginExecutionCommandWithPendingResult = executionCommand.isPluginExecutionCommandWithPendingResult();
|
boolean isPluginExecutionCommandWithPendingResult = executionCommand.isPluginExecutionCommandWithPendingResult();
|
||||||
|
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
|
// 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, !isPluginExecutionCommandWithPendingResult));
|
Logger.logErrorExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true,
|
||||||
|
!isPluginExecutionCommandWithPendingResult, isExecutionCommandLoggingEnabled));
|
||||||
|
|
||||||
// If execution command was started by a plugin which expects the result back
|
// If execution command was started by a plugin which expects the result back
|
||||||
if (isPluginExecutionCommandWithPendingResult) {
|
if (isPluginExecutionCommandWithPendingResult) {
|
||||||
@@ -146,11 +152,12 @@ public class PluginUtils {
|
|||||||
setPluginResultDirectoryVariables(executionCommand);
|
setPluginResultDirectoryVariables(executionCommand);
|
||||||
|
|
||||||
// Send result to caller
|
// Send result to caller
|
||||||
error = ResultSender.sendCommandResultData(context, logTag, executionCommand.getCommandIdAndLabelLogString(), executionCommand.resultConfig, executionCommand.resultData);
|
error = ResultSender.sendCommandResultData(context, logTag, executionCommand.getCommandIdAndLabelLogString(),
|
||||||
|
executionCommand.resultConfig, executionCommand.resultData, isExecutionCommandLoggingEnabled);
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
// error will be added to existing Errors
|
// error will be added to existing Errors
|
||||||
resultData.setStateFailed(error);
|
resultData.setStateFailed(error);
|
||||||
Logger.logErrorExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true, true));
|
Logger.logErrorExtended(logTag, ExecutionCommand.getExecutionOutputLogString(executionCommand, true, true, isExecutionCommandLoggingEnabled));
|
||||||
forceNotification = true;
|
forceNotification = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +178,7 @@ public class PluginUtils {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set variables which will be used by {@link ResultSender#sendCommandResultData(Context, String, String, ResultConfig, ResultData)}
|
/** Set variables which will be used by {@link ResultSender#sendCommandResultData(Context, String, String, ResultConfig, ResultData, boolean)}
|
||||||
* to send back the result via {@link ResultConfig#resultPendingIntent}. */
|
* to send back the result via {@link ResultConfig#resultPendingIntent}. */
|
||||||
public static void setPluginResultPendingIntentVariables(ExecutionCommand executionCommand) {
|
public static void setPluginResultPendingIntentVariables(ExecutionCommand executionCommand) {
|
||||||
ResultConfig resultConfig = executionCommand.resultConfig;
|
ResultConfig resultConfig = executionCommand.resultConfig;
|
||||||
@@ -186,7 +193,7 @@ public class PluginUtils {
|
|||||||
resultConfig.resultErrmsgKey = TERMUX_SERVICE.EXTRA_PLUGIN_RESULT_BUNDLE_ERRMSG;
|
resultConfig.resultErrmsgKey = TERMUX_SERVICE.EXTRA_PLUGIN_RESULT_BUNDLE_ERRMSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Set variables which will be used by {@link ResultSender#sendCommandResultData(Context, String, String, ResultConfig, ResultData)}
|
/** Set variables which will be used by {@link ResultSender#sendCommandResultData(Context, String, String, ResultConfig, ResultData, boolean)}
|
||||||
* to send back the result by writing it to files in {@link ResultConfig#resultDirectoryPath}. */
|
* to send back the result by writing it to files in {@link ResultConfig#resultDirectoryPath}. */
|
||||||
public static void setPluginResultDirectoryVariables(ExecutionCommand executionCommand) {
|
public static void setPluginResultDirectoryVariables(ExecutionCommand executionCommand) {
|
||||||
ResultConfig resultConfig = executionCommand.resultConfig;
|
ResultConfig resultConfig = executionCommand.resultConfig;
|
||||||
|
@@ -436,4 +436,11 @@ public class Logger {
|
|||||||
return (logLevel != null && logLevel >= LOG_LEVEL_OFF && logLevel <= MAX_LOG_LEVEL);
|
return (logLevel != null && logLevel >= LOG_LEVEL_OFF && logLevel <= MAX_LOG_LEVEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Check if custom log level is valid and >= {@link #CURRENT_LOG_LEVEL}. If custom log level is
|
||||||
|
* not valid then {@link #LOG_LEVEL_VERBOSE} must be >= {@link #CURRENT_LOG_LEVEL}. */
|
||||||
|
public static boolean shouldEnableLoggingForCustomLogLevel(Integer customLogLevel) {
|
||||||
|
customLogLevel = Logger.isLogLevelValid(customLogLevel) ? customLogLevel: Logger.LOG_LEVEL_VERBOSE;
|
||||||
|
return (customLogLevel >= CURRENT_LOG_LEVEL);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -85,8 +85,10 @@ public class ExecutionCommand {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link ExecutionCommand} custom log level for background {@link com.termux.shared.shell.TermuxTask}
|
* The {@link ExecutionCommand} custom log level for background {@link com.termux.shared.shell.TermuxTask}
|
||||||
* commands. By default, @link com.termux.shared.shell.StreamGobbler} only logs if {@link Logger}
|
* commands. By default, @link com.termux.shared.shell.StreamGobbler} only logs stdout and
|
||||||
* `CURRENT_LOG_LEVEL` is >= {@link Logger#LOG_LEVEL_VERBOSE}.
|
* stderr if {@link Logger} `CURRENT_LOG_LEVEL` is >= {@link Logger#LOG_LEVEL_VERBOSE} and
|
||||||
|
* {@link com.termux.shared.shell.TermuxTask} only logs stdin if `CURRENT_LOG_LEVEL` is >=
|
||||||
|
* {@link Logger#LOG_LEVEL_DEBUG}.
|
||||||
*/
|
*/
|
||||||
public Integer backgroundCustomLogLevel;
|
public Integer backgroundCustomLogLevel;
|
||||||
|
|
||||||
@@ -242,7 +244,7 @@ public class ExecutionCommand {
|
|||||||
if (!hasExecuted())
|
if (!hasExecuted())
|
||||||
return getExecutionInputLogString(this, true, true);
|
return getExecutionInputLogString(this, true, true);
|
||||||
else {
|
else {
|
||||||
return getExecutionOutputLogString(this, true, true);
|
return getExecutionOutputLogString(this, true, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,9 +300,10 @@ public class ExecutionCommand {
|
|||||||
* @param executionCommand The {@link ExecutionCommand} to convert.
|
* @param executionCommand The {@link ExecutionCommand} to convert.
|
||||||
* @param ignoreNull Set to {@code true} if non-critical {@code null} values are to be ignored.
|
* @param ignoreNull Set to {@code true} if non-critical {@code null} values are to be ignored.
|
||||||
* @param logResultData Set to {@code true} if {@link #resultData} should be logged.
|
* @param logResultData Set to {@code true} if {@link #resultData} should be logged.
|
||||||
|
* @param logStdoutAndStderr Set to {@code true} if {@link ResultData#stdout} and {@link ResultData#stderr} should be logged.
|
||||||
* @return Returns the log friendly {@link String}.
|
* @return Returns the log friendly {@link String}.
|
||||||
*/
|
*/
|
||||||
public static String getExecutionOutputLogString(final ExecutionCommand executionCommand, boolean ignoreNull, boolean logResultData) {
|
public static String getExecutionOutputLogString(final ExecutionCommand executionCommand, boolean ignoreNull, boolean logResultData, boolean logStdoutAndStderr) {
|
||||||
if (executionCommand == null) return "null";
|
if (executionCommand == null) return "null";
|
||||||
|
|
||||||
StringBuilder logString = new StringBuilder();
|
StringBuilder logString = new StringBuilder();
|
||||||
@@ -311,7 +314,7 @@ public class ExecutionCommand {
|
|||||||
logString.append("\n").append(executionCommand.getCurrentStateLogString());
|
logString.append("\n").append(executionCommand.getCurrentStateLogString());
|
||||||
|
|
||||||
if (logResultData)
|
if (logResultData)
|
||||||
logString.append("\n").append(ResultData.getResultDataLogString(executionCommand.resultData, ignoreNull));
|
logString.append("\n").append(ResultData.getResultDataLogString(executionCommand.resultData, logStdoutAndStderr));
|
||||||
|
|
||||||
return logString.toString();
|
return logString.toString();
|
||||||
}
|
}
|
||||||
@@ -328,7 +331,7 @@ public class ExecutionCommand {
|
|||||||
StringBuilder logString = new StringBuilder();
|
StringBuilder logString = new StringBuilder();
|
||||||
|
|
||||||
logString.append(getExecutionInputLogString(executionCommand, false, true));
|
logString.append(getExecutionInputLogString(executionCommand, false, true));
|
||||||
logString.append(getExecutionOutputLogString(executionCommand, false, true));
|
logString.append(getExecutionOutputLogString(executionCommand, false, true, true));
|
||||||
|
|
||||||
logString.append("\n").append(executionCommand.getCommandDescriptionLogString());
|
logString.append("\n").append(executionCommand.getCommandDescriptionLogString());
|
||||||
logString.append("\n").append(executionCommand.getCommandHelpLogString());
|
logString.append("\n").append(executionCommand.getCommandHelpLogString());
|
||||||
|
@@ -133,16 +133,18 @@ public class ResultData implements Serializable {
|
|||||||
* Get a log friendly {@link String} for {@link ResultData} parameters.
|
* Get a log friendly {@link String} for {@link ResultData} parameters.
|
||||||
*
|
*
|
||||||
* @param resultData The {@link ResultData} to convert.
|
* @param resultData The {@link ResultData} to convert.
|
||||||
* @param ignoreNull Set to {@code true} if non-critical {@code null} values are to be ignored.
|
* @param logStdoutAndStderr Set to {@code true} if {@link #stdout} and {@link #stderr} should be logged.
|
||||||
* @return Returns the log friendly {@link String}.
|
* @return Returns the log friendly {@link String}.
|
||||||
*/
|
*/
|
||||||
public static String getResultDataLogString(final ResultData resultData, boolean ignoreNull) {
|
public static String getResultDataLogString(final ResultData resultData, boolean logStdoutAndStderr) {
|
||||||
if (resultData == null) return "null";
|
if (resultData == null) return "null";
|
||||||
|
|
||||||
StringBuilder logString = new StringBuilder();
|
StringBuilder logString = new StringBuilder();
|
||||||
|
|
||||||
|
if (logStdoutAndStderr) {
|
||||||
logString.append("\n").append(resultData.getStdoutLogString());
|
logString.append("\n").append(resultData.getStdoutLogString());
|
||||||
logString.append("\n").append(resultData.getStderrLogString());
|
logString.append("\n").append(resultData.getStderrLogString());
|
||||||
|
}
|
||||||
logString.append("\n").append(resultData.getExitCodeLogString());
|
logString.append("\n").append(resultData.getExitCodeLogString());
|
||||||
|
|
||||||
logString.append("\n\n").append(getErrorsListLogString(resultData));
|
logString.append("\n\n").append(getErrorsListLogString(resultData));
|
||||||
|
@@ -34,22 +34,24 @@ public class ResultSender {
|
|||||||
* @param label The label for the command.
|
* @param label The label for the command.
|
||||||
* @param resultConfig The {@link ResultConfig} object containing information on how to send the result.
|
* @param resultConfig The {@link ResultConfig} object containing information on how to send the result.
|
||||||
* @param resultData The {@link ResultData} object containing result data.
|
* @param resultData The {@link ResultData} object containing result data.
|
||||||
|
* @param logStdoutAndStderr Set to {@code true} if {@link ResultData#stdout} and {@link ResultData#stderr}
|
||||||
|
* should be logged.
|
||||||
* @return Returns the {@link Error} if failed to send the result, otherwise {@code null}.
|
* @return Returns the {@link Error} if failed to send the result, otherwise {@code null}.
|
||||||
*/
|
*/
|
||||||
public static Error sendCommandResultData(Context context, String logTag, String label, ResultConfig resultConfig, ResultData resultData) {
|
public static Error sendCommandResultData(Context context, String logTag, String label, ResultConfig resultConfig, ResultData resultData, boolean logStdoutAndStderr) {
|
||||||
if (context == null || resultConfig == null || resultData == null)
|
if (context == null || resultConfig == null || resultData == null)
|
||||||
return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETERS.getError("context, resultConfig or resultData", "sendCommandResultData");
|
return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETERS.getError("context, resultConfig or resultData", "sendCommandResultData");
|
||||||
|
|
||||||
Error error;
|
Error error;
|
||||||
|
|
||||||
if (resultConfig.resultPendingIntent != null) {
|
if (resultConfig.resultPendingIntent != null) {
|
||||||
error = sendCommandResultDataWithPendingIntent(context, logTag, label, resultConfig, resultData);
|
error = sendCommandResultDataWithPendingIntent(context, logTag, label, resultConfig, resultData, logStdoutAndStderr);
|
||||||
if (error != null || resultConfig.resultDirectoryPath == null)
|
if (error != null || resultConfig.resultDirectoryPath == null)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultConfig.resultDirectoryPath != null) {
|
if (resultConfig.resultDirectoryPath != null) {
|
||||||
return sendCommandResultDataToDirectory(context, logTag, label, resultConfig, resultData);
|
return sendCommandResultDataToDirectory(context, logTag, label, resultConfig, resultData, logStdoutAndStderr);
|
||||||
} else {
|
} else {
|
||||||
return FunctionErrno.ERRNO_UNSET_PARAMETERS.getError("resultConfig.resultPendingIntent or resultConfig.resultDirectoryPath", "sendCommandResultData");
|
return FunctionErrno.ERRNO_UNSET_PARAMETERS.getError("resultConfig.resultPendingIntent or resultConfig.resultDirectoryPath", "sendCommandResultData");
|
||||||
}
|
}
|
||||||
@@ -63,15 +65,17 @@ public class ResultSender {
|
|||||||
* @param label The label for the command.
|
* @param label The label for the command.
|
||||||
* @param resultConfig The {@link ResultConfig} object containing information on how to send the result.
|
* @param resultConfig The {@link ResultConfig} object containing information on how to send the result.
|
||||||
* @param resultData The {@link ResultData} object containing result data.
|
* @param resultData The {@link ResultData} object containing result data.
|
||||||
|
* @param logStdoutAndStderr Set to {@code true} if {@link ResultData#stdout} and {@link ResultData#stderr}
|
||||||
|
* should be logged.
|
||||||
* @return Returns the {@link Error} if failed to send the result, otherwise {@code null}.
|
* @return Returns the {@link Error} if failed to send the result, otherwise {@code null}.
|
||||||
*/
|
*/
|
||||||
public static Error sendCommandResultDataWithPendingIntent(Context context, String logTag, String label, ResultConfig resultConfig, ResultData resultData) {
|
public static Error sendCommandResultDataWithPendingIntent(Context context, String logTag, String label, ResultConfig resultConfig, ResultData resultData, boolean logStdoutAndStderr) {
|
||||||
if (context == null || resultConfig == null || resultData == null || resultConfig.resultPendingIntent == null || resultConfig.resultBundleKey == null)
|
if (context == null || resultConfig == null || resultData == null || resultConfig.resultPendingIntent == null || resultConfig.resultBundleKey == null)
|
||||||
return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError("context, resultConfig, resultData, resultConfig.resultPendingIntent or resultConfig.resultBundleKey", "sendCommandResultDataWithPendingIntent");
|
return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError("context, resultConfig, resultData, resultConfig.resultPendingIntent or resultConfig.resultBundleKey", "sendCommandResultDataWithPendingIntent");
|
||||||
|
|
||||||
logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
||||||
|
|
||||||
Logger.logDebugExtended(logTag, "Sending result for command \"" + label + "\":\n" + resultConfig.toString() + "\n" + resultData.toString());
|
Logger.logDebugExtended(logTag, "Sending result for command \"" + label + "\":\n" + resultConfig.toString() + "\n" + ResultData.getResultDataLogString(resultData, logStdoutAndStderr));
|
||||||
|
|
||||||
String resultDataStdout = resultData.stdout.toString();
|
String resultDataStdout = resultData.stdout.toString();
|
||||||
String resultDataStderr = resultData.stderr.toString();
|
String resultDataStderr = resultData.stderr.toString();
|
||||||
@@ -152,9 +156,11 @@ public class ResultSender {
|
|||||||
* @param label The label for the command.
|
* @param label The label for the command.
|
||||||
* @param resultConfig The {@link ResultConfig} object containing information on how to send the result.
|
* @param resultConfig The {@link ResultConfig} object containing information on how to send the result.
|
||||||
* @param resultData The {@link ResultData} object containing result data.
|
* @param resultData The {@link ResultData} object containing result data.
|
||||||
|
* @param logStdoutAndStderr Set to {@code true} if {@link ResultData#stdout} and {@link ResultData#stderr}
|
||||||
|
* should be logged.
|
||||||
* @return Returns the {@link Error} if failed to send the result, otherwise {@code null}.
|
* @return Returns the {@link Error} if failed to send the result, otherwise {@code null}.
|
||||||
*/
|
*/
|
||||||
public static Error sendCommandResultDataToDirectory(Context context, String logTag, String label, ResultConfig resultConfig, ResultData resultData) {
|
public static Error sendCommandResultDataToDirectory(Context context, String logTag, String label, ResultConfig resultConfig, ResultData resultData, boolean logStdoutAndStderr) {
|
||||||
if (context == null || resultConfig == null || resultData == null || DataUtils.isNullOrEmpty(resultConfig.resultDirectoryPath))
|
if (context == null || resultConfig == null || resultData == null || DataUtils.isNullOrEmpty(resultConfig.resultDirectoryPath))
|
||||||
return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError("context, resultConfig, resultData or resultConfig.resultDirectoryPath", "sendCommandResultDataToDirectory");
|
return FunctionErrno.ERRNO_NULL_OR_EMPTY_PARAMETER.getError("context, resultConfig, resultData or resultConfig.resultDirectoryPath", "sendCommandResultDataToDirectory");
|
||||||
|
|
||||||
@@ -177,7 +183,7 @@ public class ResultSender {
|
|||||||
|
|
||||||
resultConfig.resultDirectoryPath = FileUtils.getCanonicalPath(resultConfig.resultDirectoryPath, null);
|
resultConfig.resultDirectoryPath = FileUtils.getCanonicalPath(resultConfig.resultDirectoryPath, null);
|
||||||
|
|
||||||
Logger.logDebugExtended(logTag, "Writing result for command \"" + label + "\":\n" + resultConfig.toString() + "\n" + resultData.toString());
|
Logger.logDebugExtended(logTag, "Writing result for command \"" + label + "\":\n" + resultConfig.toString() + "\n" + ResultData.getResultDataLogString(resultData, logStdoutAndStderr));
|
||||||
|
|
||||||
// If resultDirectoryPath is not a directory, or is not readable or writable, then just return
|
// If resultDirectoryPath is not a directory, or is not readable or writable, then just return
|
||||||
// Creation of missing directory and setting of read, write and execute permissions are
|
// Creation of missing directory and setting of read, write and execute permissions are
|
||||||
|
@@ -88,7 +88,7 @@ public class StreamGobbler extends Thread {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final OnStreamClosedListener streamClosedListener;
|
private final OnStreamClosedListener streamClosedListener;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Integer mLlogLevel;
|
private final Integer mLogLevel;
|
||||||
private volatile boolean active = true;
|
private volatile boolean active = true;
|
||||||
private volatile boolean calledOnClose = false;
|
private volatile boolean calledOnClose = false;
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ public class StreamGobbler extends Thread {
|
|||||||
* @param shell Name of the shell
|
* @param shell Name of the shell
|
||||||
* @param inputStream InputStream to read from
|
* @param inputStream InputStream to read from
|
||||||
* @param outputList {@literal List<String>} to write to, or null
|
* @param outputList {@literal List<String>} to write to, or null
|
||||||
* @param logLevel The custom log level to use for logging by command output. If set to
|
* @param logLevel The custom log level to use for logging the command output. If set to
|
||||||
* {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used.
|
* {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used.
|
||||||
*/
|
*/
|
||||||
@AnyThread
|
@AnyThread
|
||||||
@@ -121,7 +121,7 @@ public class StreamGobbler extends Thread {
|
|||||||
stringWriter = null;
|
stringWriter = null;
|
||||||
lineListener = null;
|
lineListener = null;
|
||||||
|
|
||||||
mLlogLevel = logLevel;
|
mLogLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -136,7 +136,7 @@ public class StreamGobbler extends Thread {
|
|||||||
* @param shell Name of the shell
|
* @param shell Name of the shell
|
||||||
* @param inputStream InputStream to read from
|
* @param inputStream InputStream to read from
|
||||||
* @param outputString {@literal List<String>} to write to, or null
|
* @param outputString {@literal List<String>} to write to, or null
|
||||||
* @param logLevel The custom log level to use for logging by command output. If set to
|
* @param logLevel The custom log level to use for logging the command output. If set to
|
||||||
* {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used.
|
* {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used.
|
||||||
*/
|
*/
|
||||||
@AnyThread
|
@AnyThread
|
||||||
@@ -153,7 +153,7 @@ public class StreamGobbler extends Thread {
|
|||||||
stringWriter = outputString;
|
stringWriter = outputString;
|
||||||
lineListener = null;
|
lineListener = null;
|
||||||
|
|
||||||
mLlogLevel = logLevel;
|
mLogLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,7 +167,7 @@ public class StreamGobbler extends Thread {
|
|||||||
* @param inputStream InputStream to read from
|
* @param inputStream InputStream to read from
|
||||||
* @param onLineListener OnLineListener callback
|
* @param onLineListener OnLineListener callback
|
||||||
* @param onStreamClosedListener OnStreamClosedListener callback
|
* @param onStreamClosedListener OnStreamClosedListener callback
|
||||||
* @param logLevel The custom log level to use for logging by command output. If set to
|
* @param logLevel The custom log level to use for logging the command output. If set to
|
||||||
* {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used.
|
* {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used.
|
||||||
*/
|
*/
|
||||||
@AnyThread
|
@AnyThread
|
||||||
@@ -185,28 +185,22 @@ public class StreamGobbler extends Thread {
|
|||||||
stringWriter = null;
|
stringWriter = null;
|
||||||
lineListener = onLineListener;
|
lineListener = onLineListener;
|
||||||
|
|
||||||
mLlogLevel = logLevel;
|
mLogLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String defaultLogTag = Logger.DEFAULT_LOG_TAG;
|
String defaultLogTag = Logger.DEFAULT_LOG_TAG;
|
||||||
int currentLogLevel = Logger.getLogLevel();
|
boolean loggingEnabled = Logger.shouldEnableLoggingForCustomLogLevel(mLogLevel);
|
||||||
|
if (loggingEnabled)
|
||||||
int customLogLevel;
|
Logger.logVerbose(LOG_TAG, "Using custom log level: " + mLogLevel + ", current log level: " + Logger.getLogLevel());
|
||||||
if (Logger.isLogLevelValid(mLlogLevel)) {
|
|
||||||
customLogLevel = mLlogLevel;
|
|
||||||
Logger.logVerbose(LOG_TAG, "Using custom log level: " + customLogLevel + ", current log level: " + currentLogLevel);
|
|
||||||
} else {
|
|
||||||
customLogLevel = Logger.LOG_LEVEL_VERBOSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// keep reading the InputStream until it ends (or an error occurs)
|
// keep reading the InputStream until it ends (or an error occurs)
|
||||||
// optionally pausing when a command is executed that consumes the InputStream itself
|
// optionally pausing when a command is executed that consumes the InputStream itself
|
||||||
try {
|
try {
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
if (customLogLevel >= currentLogLevel)
|
if (loggingEnabled)
|
||||||
Logger.logVerboseForce(defaultLogTag + "Command", String.format(Locale.ENGLISH, "[%s] %s", shell, line)); // This will get truncated by LOGGER_ENTRY_MAX_LEN, likely 4KB
|
Logger.logVerboseForce(defaultLogTag + "Command", String.format(Locale.ENGLISH, "[%s] %s", shell, line)); // This will get truncated by LOGGER_ENTRY_MAX_LEN, likely 4KB
|
||||||
|
|
||||||
if (stringWriter != null) stringWriter.append(line).append("\n");
|
if (stringWriter != null) stringWriter.append(line).append("\n");
|
||||||
|
@@ -82,8 +82,8 @@ public final class TermuxTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No need to log stdin if logging is disabled, like for app internal scripts
|
// No need to log stdin if logging is disabled, like for app internal scripts
|
||||||
int customLogLevel = Logger.isLogLevelValid(executionCommand.backgroundCustomLogLevel) ? executionCommand.backgroundCustomLogLevel: Logger.LOG_LEVEL_VERBOSE;
|
Logger.logDebugExtended(LOG_TAG, ExecutionCommand.getExecutionInputLogString(executionCommand,
|
||||||
Logger.logDebugExtended(LOG_TAG, ExecutionCommand.getExecutionInputLogString(executionCommand, true, customLogLevel >= Logger.getLogLevel()));
|
true, Logger.shouldEnableLoggingForCustomLogLevel(executionCommand.backgroundCustomLogLevel)));
|
||||||
|
|
||||||
String taskName = ShellUtils.getExecutableBasename(executionCommand.executable);
|
String taskName = ShellUtils.getExecutableBasename(executionCommand.executable);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user