From 60f37bde8dd415f71acc8d4e6feb08dff78e2fb3 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Fri, 20 Aug 2021 01:15:01 +0500 Subject: [PATCH] Changed!: StreamGobbler needs to be passed log level parameter When `Logger.CURRENT_LOG_LEVEL` set by user is `Logger.LOG_VERBOSE`, then background (not foreground sessions) command output was being logged to logcat, however, if command outputted too much data to logcat, then logcat clients like in Android Studio would crash. Also if a logcat dump is being taken inside termux, then duplicate lines would occur, first one due to of original entry, and second one due to StreamGobbler logging output at verbose level for logcat command. This would be a concern for plugins as well like `RUN_COMMAND` intent or Termux:Tasker, etc if they ran commands with lot of data and user had set log level to verbose. For plugins, TermuxService now supports `com.termux.execute.background_custom_log_level` `String` extra for custom log level. Termux:Tasker, etc will have to be updated with support. For `RUN_COMMAND` intent, the `com.termux.RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL` `String` extra is now provided to set custom log level for only the command output. Check `TermuxConstants`. So one can pass a custom log level that is `>=` to the log level set it termux settings where (OFF=0, NORMAL=1, DEBUG=2, VERBOSE=3). If you pass `0`, it will completely disable logging. If you pass `1`, logging will only be enabled if log level in termux settings is `NORMAL` or higher. If custom log level is not passed, then old behaviour will remain and log level in termux settings must be `VERBOSE` or higher for logging to be enabled. Note that the log entries will still be logged with priority `Log.VERBOSE` regardless of log level, i.e `logcat` will have `V/`. The entries logcat component has now changed from `StreamGobbler` to `TermuxCommand`. For output at `stdout`, the entry format is `[-stdout] ...` and for the output at `stderr`, the entry format is `[-stderr] ...`. The `` will be process id as an integer that was started by termux. For example: `V/TermuxCommand: [66666-stdout] ...`. While doing this I realize that instead of using `am` command to send messages back to tasker, you can use tasker `Logcat Entry` profile event to listen to messages from termux at both `stdout` and `stderr`. This might be faster than `am` command intent systems or at least possibly more convenient in some use cases. So setup a profile with the `Component` value set to `TermuxCommand` and `Filter` value set to `-E 'TermuxCommand: \[[0-9]+-((stdout)|(stderr))\] message_tag: .*'` and enable the `Grep Filter` toggle so that entry matching is done in native code. Check https://github.com/joaomgcd/TaskerDocumentation/blob/master/en/help/logcat%20info.md for details. Also enable `Enforce Task Order` in profile settings and set collision handling to `Run Both Together` so that if two or more entries are sent quickly, entry task is run for all. Tasker currently (v5.13.16) is not maintaining order of entry tasks despite the setting. Then you can send an intent from tasker via `Run Shell` action with `root` (since `am` command won't work without it on android >=8) or normally in termux from a script, you should be able to receive the entries as `@lc_text` in entry task of tasker `Logcat Entry` profile. The following just passes two `echo` commands to `bash` as a script via `stdin`. If you don't have root, then you can call a wrapper script with `TermuxCommand` function in `Tasker Function` action that sends another `RUN_COMMAND` intent with termux provide `am` command which will work without root. ``` am startservice --user 0 -n com.termux/com.termux.app.RunCommandService -a com.termux.RUN_COMMAND --es com.termux.RUN_COMMAND_PATH '/data/data/com.termux/files/usr/bin/bash' --es com.termux.RUN_COMMAND_STDIN 'echo "message_tag: Sending message from tasker to termux"' --ez com.termux.RUN_COMMAND_BACKGROUND true --es com.termux.RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL '1' ``` --- .../com/termux/app/RunCommandService.java | 2 + .../java/com/termux/app/TermuxService.java | 1 + .../com/termux/shared/data/DataUtils.java | 15 ++++-- .../com/termux/shared/data/IntentUtils.java | 23 ++++++++++ .../java/com/termux/shared/logger/Logger.java | 16 ++++--- .../shared/models/ExecutionCommand.java | 17 +++++++ .../termux/shared/shell/StreamGobbler.java | 46 +++++++++++++++---- .../com/termux/shared/shell/TermuxTask.java | 4 +- .../termux/shared/termux/TermuxConstants.java | 12 ++++- .../com/termux/shared/termux/TermuxUtils.java | 1 + 10 files changed, 115 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/termux/app/RunCommandService.java b/app/src/main/java/com/termux/app/RunCommandService.java index c5c79f939d..2d1d3fe22c 100644 --- a/app/src/main/java/com/termux/app/RunCommandService.java +++ b/app/src/main/java/com/termux/app/RunCommandService.java @@ -101,6 +101,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { executionCommand.stdin = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_STDIN, null); executionCommand.workingDirectory = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_WORKDIR, null); executionCommand.inBackground = intent.getBooleanExtra(RUN_COMMAND_SERVICE.EXTRA_BACKGROUND, false); + executionCommand.backgroundCustomLogLevel = IntentUtils.getIntegerExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, null); executionCommand.sessionAction = intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_SESSION_ACTION); executionCommand.commandLabel = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_LABEL, "RUN_COMMAND Execution Intent Command"); executionCommand.commandDescription = IntentUtils.getStringExtraIfSet(intent, RUN_COMMAND_SERVICE.EXTRA_COMMAND_DESCRIPTION, null); @@ -197,6 +198,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { execIntent.putExtra(TERMUX_SERVICE.EXTRA_STDIN, executionCommand.stdin); if (executionCommand.workingDirectory != null && !executionCommand.workingDirectory.isEmpty()) execIntent.putExtra(TERMUX_SERVICE.EXTRA_WORKDIR, executionCommand.workingDirectory); execIntent.putExtra(TERMUX_SERVICE.EXTRA_BACKGROUND, executionCommand.inBackground); + execIntent.putExtra(TERMUX_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, DataUtils.getStringFromInteger(executionCommand.backgroundCustomLogLevel, null)); execIntent.putExtra(TERMUX_SERVICE.EXTRA_SESSION_ACTION, executionCommand.sessionAction); execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_LABEL, executionCommand.commandLabel); execIntent.putExtra(TERMUX_SERVICE.EXTRA_COMMAND_DESCRIPTION, executionCommand.commandDescription); diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java index fe0b9a5b61..06a25754df 100644 --- a/app/src/main/java/com/termux/app/TermuxService.java +++ b/app/src/main/java/com/termux/app/TermuxService.java @@ -364,6 +364,7 @@ private void actionServiceExecute(Intent intent) { executionCommand.arguments = IntentUtils.getStringArrayExtraIfSet(intent, TERMUX_SERVICE.EXTRA_ARGUMENTS, null); if (executionCommand.inBackground) executionCommand.stdin = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_STDIN, null); + executionCommand.backgroundCustomLogLevel = IntentUtils.getIntegerExtraIfSet(intent, TERMUX_SERVICE.EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL, null); } executionCommand.workingDirectory = IntentUtils.getStringExtraIfSet(intent, TERMUX_SERVICE.EXTRA_WORKDIR, null); diff --git a/termux-shared/src/main/java/com/termux/shared/data/DataUtils.java b/termux-shared/src/main/java/com/termux/shared/data/DataUtils.java index 60bb9fca96..9196910360 100644 --- a/termux-shared/src/main/java/com/termux/shared/data/DataUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/data/DataUtils.java @@ -4,10 +4,6 @@ import androidx.annotation.Nullable; -import java.util.LinkedHashSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class DataUtils { public static final int TRANSACTION_SIZE_LIMIT_IN_BYTES = 100 * 1024; // 100KB @@ -97,6 +93,17 @@ public static int getIntFromString(String value, int def) { } } + /** + * Get the {@code String} from an {@link Integer}. + * + * @param value The {@link Integer} value. + * @param def The default {@link String} value. + * @return Returns {@code value} if it is not {@code null}, otherwise returns {@code def}. + */ + public static String getStringFromInteger(Integer value, String def) { + return (value == null) ? def : String.valueOf((int) value); + } + /** * Get the {@code hex string} from a {@link byte[]}. * diff --git a/termux-shared/src/main/java/com/termux/shared/data/IntentUtils.java b/termux-shared/src/main/java/com/termux/shared/data/IntentUtils.java index 885eb4232f..0c692fc352 100644 --- a/termux-shared/src/main/java/com/termux/shared/data/IntentUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/data/IntentUtils.java @@ -49,6 +49,29 @@ public static String getStringExtraIfSet(@NonNull Intent intent, String key, Str return value; } + /** + * Get an {@link Integer} from an {@link Intent} stored as a {@link String} extra if its not + * {@code null} or empty. + * + * @param intent The {@link Intent} to get the extra from. + * @param key The {@link String} key name. + * @param def The default value if extra is not set. + * @return Returns the {@link Integer} extra if set, otherwise {@code null}. + */ + public static Integer getIntegerExtraIfSet(@NonNull Intent intent, String key, Integer def) { + try { + String value = intent.getStringExtra(key); + if (value == null || value.isEmpty()) { + return def; + } + + return Integer.parseInt(value); + } + catch (Exception e) { + return def; + } + } + /** diff --git a/termux-shared/src/main/java/com/termux/shared/logger/Logger.java b/termux-shared/src/main/java/com/termux/shared/logger/Logger.java index 2202a7bcde..10e777f848 100644 --- a/termux-shared/src/main/java/com/termux/shared/logger/Logger.java +++ b/termux-shared/src/main/java/com/termux/shared/logger/Logger.java @@ -50,16 +50,16 @@ public class Logger { - public static void logMessage(int logLevel, String tag, String message) { - if (logLevel == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) + public static void logMessage(int logPriority, String tag, String message) { + if (logPriority == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) Log.e(getFullTag(tag), message); - else if (logLevel == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) + else if (logPriority == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) Log.w(getFullTag(tag), message); - else if (logLevel == Log.INFO && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) + else if (logPriority == Log.INFO && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) Log.i(getFullTag(tag), message); - else if (logLevel == Log.DEBUG && CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) + else if (logPriority == Log.DEBUG && CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) Log.d(getFullTag(tag), message); - else if (logLevel == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE) + else if (logPriority == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE) Log.v(getFullTag(tag), message); } @@ -187,6 +187,10 @@ public static void logVerboseExtended(String message) { logExtendedMessage(Log.VERBOSE, DEFAULT_LOG_TAG, message); } + public static void logVerboseForce(String tag, String message) { + Log.v(tag, message); + } + public static void logErrorAndShowToast(Context context, String tag, String message) { diff --git a/termux-shared/src/main/java/com/termux/shared/models/ExecutionCommand.java b/termux-shared/src/main/java/com/termux/shared/models/ExecutionCommand.java index 77f7716078..d3611a5364 100644 --- a/termux-shared/src/main/java/com/termux/shared/models/ExecutionCommand.java +++ b/termux-shared/src/main/java/com/termux/shared/models/ExecutionCommand.java @@ -83,6 +83,12 @@ public int getValue() { /** If the {@link ExecutionCommand} is meant to start a failsafe terminal session. */ public boolean isFailsafe; + /** + * 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} + * `CURRENT_LOG_LEVEL` is >= {@link Logger#LOG_LEVEL_VERBOSE}. + */ + public Integer backgroundCustomLogLevel; /** The session action of foreground commands. */ public String sessionAction; @@ -264,6 +270,9 @@ public static String getExecutionInputLogString(final ExecutionCommand execution logString.append("\n").append(executionCommand.getInBackgroundLogString()); logString.append("\n").append(executionCommand.getIsFailsafeLogString()); + if (executionCommand.inBackground && (!ignoreNull || executionCommand.backgroundCustomLogLevel != null)) + logString.append("\n").append(executionCommand.getBackgroundCustomLogLevelLogString()); + if (!ignoreNull || executionCommand.sessionAction != null) logString.append("\n").append(executionCommand.getSessionActionLogString()); @@ -346,6 +355,10 @@ public static String getExecutionCommandMarkdownString(final ExecutionCommand ex markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Working Directory", executionCommand.workingDirectory, "-")); markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("inBackground", executionCommand.inBackground, "-")); markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("isFailsafe", executionCommand.isFailsafe, "-")); + + if (executionCommand.inBackground && executionCommand.backgroundCustomLogLevel != null) + markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Background Custom Log Level", executionCommand.backgroundCustomLogLevel, "-")); + markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Session Action", executionCommand.sessionAction, "-")); @@ -418,6 +431,10 @@ public String getIsFailsafeLogString() { return "isFailsafe: `" + isFailsafe + "`"; } + public String getBackgroundCustomLogLevelLogString() { + return "Background Custom Log Level: `" + backgroundCustomLogLevel + "`"; + } + public String getSessionActionLogString() { return Logger.getSingleLineLogStringEntry("Session Action", sessionAction, "-"); } diff --git a/termux-shared/src/main/java/com/termux/shared/shell/StreamGobbler.java b/termux-shared/src/main/java/com/termux/shared/shell/StreamGobbler.java index d14ce7ab27..a8e1ca9136 100644 --- a/termux-shared/src/main/java/com/termux/shared/shell/StreamGobbler.java +++ b/termux-shared/src/main/java/com/termux/shared/shell/StreamGobbler.java @@ -87,6 +87,8 @@ public interface OnStreamClosedListener { private final OnLineListener lineListener; @Nullable private final OnStreamClosedListener streamClosedListener; + @Nullable + private final Integer mLlogLevel; private volatile boolean active = true; private volatile boolean calledOnClose = false; @@ -102,9 +104,13 @@ public interface OnStreamClosedListener { * @param shell Name of the shell * @param inputStream InputStream to read from * @param outputList {@literal List} to write to, or null + * @param logLevel The custom log level to use for logging by command output. If set to + * {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used. */ @AnyThread - public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @Nullable List outputList) { + public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, + @Nullable List outputList, + @Nullable Integer logLevel) { super("Gobbler#" + incThreadCounter()); this.shell = shell; this.inputStream = inputStream; @@ -114,6 +120,8 @@ public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @N listWriter = outputList; stringWriter = null; lineListener = null; + + mLlogLevel = logLevel; } /** @@ -128,9 +136,13 @@ public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @N * @param shell Name of the shell * @param inputStream InputStream to read from * @param outputString {@literal List} to write to, or null + * @param logLevel The custom log level to use for logging by command output. If set to + * {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used. */ @AnyThread - public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @Nullable StringBuilder outputString) { + public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, + @Nullable StringBuilder outputString, + @Nullable Integer logLevel) { super("Gobbler#" + incThreadCounter()); this.shell = shell; this.inputStream = inputStream; @@ -140,6 +152,8 @@ public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @N listWriter = null; stringWriter = outputString; lineListener = null; + + mLlogLevel = logLevel; } /** @@ -153,9 +167,14 @@ public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @N * @param inputStream InputStream to read from * @param onLineListener OnLineListener callback * @param onStreamClosedListener OnStreamClosedListener callback + * @param logLevel The custom log level to use for logging by command output. If set to + * {@code null}, then {@link Logger#LOG_LEVEL_VERBOSE} will be used. */ @AnyThread - public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @Nullable OnLineListener onLineListener, @Nullable OnStreamClosedListener onStreamClosedListener) { + public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, + @Nullable OnLineListener onLineListener, + @Nullable OnStreamClosedListener onStreamClosedListener, + @Nullable Integer logLevel) { super("Gobbler#" + incThreadCounter()); this.shell = shell; this.inputStream = inputStream; @@ -165,21 +184,30 @@ public StreamGobbler(@NonNull String shell, @NonNull InputStream inputStream, @N listWriter = null; stringWriter = null; lineListener = onLineListener; + + mLlogLevel = logLevel; } @Override public void run() { - // keep reading the InputStream until it ends (or an error occurs) - // optionally pausing when a command is executed that consumes the InputStream itself + String defaultLogTag = Logger.DEFAULT_LOG_TAG; int currentLogLevel = Logger.getLogLevel(); - int logLevelVerbose = Logger.LOG_LEVEL_VERBOSE; + int customLogLevel; + if (mLlogLevel != null && mLlogLevel >= Logger.LOG_LEVEL_OFF) { + 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) + // optionally pausing when a command is executed that consumes the InputStream itself try { String line; while ((line = reader.readLine()) != null) { - - if (currentLogLevel >= logLevelVerbose) - Logger.logVerbose(LOG_TAG, String.format(Locale.ENGLISH, "[%s] %s", shell, line)); // This will get truncated by LOGGER_ENTRY_MAX_LEN, likely 4KB + if (customLogLevel >= currentLogLevel) + 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 (listWriter != null) listWriter.add(line); diff --git a/termux-shared/src/main/java/com/termux/shared/shell/TermuxTask.java b/termux-shared/src/main/java/com/termux/shared/shell/TermuxTask.java index 4b2801eaeb..4d0658e558 100644 --- a/termux-shared/src/main/java/com/termux/shared/shell/TermuxTask.java +++ b/termux-shared/src/main/java/com/termux/shared/shell/TermuxTask.java @@ -139,8 +139,8 @@ private void executeInner(@NonNull final Context context) throws IllegalThreadSt // setup stdin, and stdout and stderr gobblers DataOutputStream STDIN = new DataOutputStream(mProcess.getOutputStream()); - StreamGobbler STDOUT = new StreamGobbler(pid + "-stdout", mProcess.getInputStream(), mExecutionCommand.resultData.stdout); - StreamGobbler STDERR = new StreamGobbler(pid + "-stderr", mProcess.getErrorStream(), mExecutionCommand.resultData.stderr); + StreamGobbler STDOUT = new StreamGobbler(pid + "-stdout", mProcess.getInputStream(), mExecutionCommand.resultData.stdout, mExecutionCommand.backgroundCustomLogLevel); + StreamGobbler STDERR = new StreamGobbler(pid + "-stderr", mProcess.getErrorStream(), mExecutionCommand.resultData.stderr, mExecutionCommand.backgroundCustomLogLevel); // start gobbling STDOUT.start(); diff --git a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java index fe531a86a3..a71337a408 100644 --- a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java @@ -12,7 +12,7 @@ import java.util.List; /* - * Version: v0.24.0 + * Version: v0.25.0 * * Changelog * @@ -172,6 +172,12 @@ * `FORMAT_FAILED_ERR__ERRMSG__STDOUT__STDERR__EXIT_CODE`, * `RESULT_FILE_ERR_PREFIX`, `RESULT_FILE_ERRMSG_PREFIX` `RESULT_FILE_STDOUT_PREFIX`, * `RESULT_FILE_STDERR_PREFIX`, `RESULT_FILE_EXIT_CODE_PREFIX`. + * + * - 0.25.0 (2021-08-19) + * - Added following to `TERMUX_APP.TERMUX_SERVICE`: + * `EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL`. + * - Added following to `TERMUX_APP.RUN_COMMAND_SERVICE`: + * `EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL`. */ /** @@ -816,6 +822,8 @@ public static final class TERMUX_SERVICE { public static final String EXTRA_WORKDIR = TERMUX_PACKAGE_NAME + ".execute.cwd"; // Default: "com.termux.execute.cwd" /** Intent {@code boolean} extra for command background mode for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */ public static final String EXTRA_BACKGROUND = TERMUX_PACKAGE_NAME + ".execute.background"; // Default: "com.termux.execute.background" + /** Intent {@code String} extra for custom log level for background commands defined by {@link com.termux.shared.logger.Logger} for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */ + public static final String EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL = TERMUX_PACKAGE_NAME + ".execute.background_custom_log_level"; // Default: "com.termux.execute.background_custom_log_level" /** Intent {@code String} extra for session action for foreground commands for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */ public static final String EXTRA_SESSION_ACTION = TERMUX_PACKAGE_NAME + ".execute.session_action"; // Default: "com.termux.execute.session_action" /** Intent {@code String} extra for label of the command for the TERMUX_SERVICE.ACTION_SERVICE_EXECUTE intent */ @@ -939,6 +947,8 @@ public static final class RUN_COMMAND_SERVICE { public static final String EXTRA_WORKDIR = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_WORKDIR"; // Default: "com.termux.RUN_COMMAND_WORKDIR" /** Intent {@code boolean} extra for whether to run command in background or foreground terminal session for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */ public static final String EXTRA_BACKGROUND = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_BACKGROUND"; // Default: "com.termux.RUN_COMMAND_BACKGROUND" + /** Intent {@code String} extra for custom log level for background commands defined by {@link com.termux.shared.logger.Logger} for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */ + public static final String EXTRA_BACKGROUND_CUSTOM_LOG_LEVEL = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL"; // Default: "com.termux.RUN_COMMAND_BACKGROUND_CUSTOM_LOG_LEVEL" /** Intent {@code String} extra for session action of foreground commands for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */ public static final String EXTRA_SESSION_ACTION = TERMUX_PACKAGE_NAME + ".RUN_COMMAND_SESSION_ACTION"; // Default: "com.termux.RUN_COMMAND_SESSION_ACTION" /** Intent {@code String} extra for label of the command for the RUN_COMMAND_SERVICE.ACTION_RUN_COMMAND intent */ diff --git a/termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java index ba623bc279..4981b206b4 100644 --- a/termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxUtils.java @@ -341,6 +341,7 @@ public static String geAPTInfoMarkdownString(@NonNull final Context context) { aptInfoScript = aptInfoScript.replaceAll(Pattern.quote("@TERMUX_PREFIX@"), TermuxConstants.TERMUX_PREFIX_DIR_PATH); ExecutionCommand executionCommand = new ExecutionCommand(1, TermuxConstants.TERMUX_BIN_PREFIX_DIR_PATH + "/bash", null, aptInfoScript, null, true, false); + executionCommand.backgroundCustomLogLevel = Logger.LOG_LEVEL_OFF; TermuxTask termuxTask = TermuxTask.execute(context, executionCommand, null, new TermuxShellEnvironmentClient(), true); if (termuxTask == null || !executionCommand.isSuccessful() || executionCommand.resultData.exitCode != 0) { Logger.logError(LOG_TAG, executionCommand.toString());