mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 10:45:23 +08:00
Move get*LogStringEntry() functions to logger class
This commit is contained in:
@@ -368,7 +368,7 @@ public class ExecutionCommand {
|
||||
}
|
||||
|
||||
public String getSessionActionLogString() {
|
||||
return getSingleLineLogStringEntry("Session Action", sessionAction, "-");
|
||||
return Logger.getSingleLineLogStringEntry("Session Action", sessionAction, "-");
|
||||
}
|
||||
|
||||
public String getPendingIntentCreatorLogString() {
|
||||
@@ -379,35 +379,35 @@ public class ExecutionCommand {
|
||||
}
|
||||
|
||||
public String getCommandDescriptionLogString() {
|
||||
return getSingleLineLogStringEntry("Command Description", commandDescription, "-");
|
||||
return Logger.getSingleLineLogStringEntry("Command Description", commandDescription, "-");
|
||||
}
|
||||
|
||||
public String getCommandHelpLogString() {
|
||||
return getSingleLineLogStringEntry("Command Help", commandHelp, "-");
|
||||
return Logger.getSingleLineLogStringEntry("Command Help", commandHelp, "-");
|
||||
}
|
||||
|
||||
public String getPluginAPIHelpLogString() {
|
||||
return getSingleLineLogStringEntry("Plugin API Help", pluginAPIHelp, "-");
|
||||
return Logger.getSingleLineLogStringEntry("Plugin API Help", pluginAPIHelp, "-");
|
||||
}
|
||||
|
||||
public String getStdoutLogString() {
|
||||
return getMultiLineLogStringEntry("Stdout", DataUtils.getTruncatedCommandOutput(stdout, DataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
return Logger.getMultiLineLogStringEntry("Stdout", DataUtils.getTruncatedCommandOutput(stdout, Logger.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
}
|
||||
|
||||
public String getStderrLogString() {
|
||||
return getMultiLineLogStringEntry("Stderr", DataUtils.getTruncatedCommandOutput(stderr, DataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
return Logger.getMultiLineLogStringEntry("Stderr", DataUtils.getTruncatedCommandOutput(stderr, Logger.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
}
|
||||
|
||||
public String getExitCodeLogString() {
|
||||
return getSingleLineLogStringEntry("Exit Code", exitCode, "-");
|
||||
return Logger.getSingleLineLogStringEntry("Exit Code", exitCode, "-");
|
||||
}
|
||||
|
||||
public String getErrCodeLogString() {
|
||||
return getSingleLineLogStringEntry("Err Code", errCode, "-");
|
||||
return Logger.getSingleLineLogStringEntry("Err Code", errCode, "-");
|
||||
}
|
||||
|
||||
public String getErrmsgLogString() {
|
||||
return getMultiLineLogStringEntry("Errmsg", errmsg, "-");
|
||||
return Logger.getMultiLineLogStringEntry("Errmsg", errmsg, "-");
|
||||
}
|
||||
|
||||
public String geStackTracesLogString() {
|
||||
@@ -475,8 +475,8 @@ public class ExecutionCommand {
|
||||
if (argumentsArray != null && argumentsArray.length != 0) {
|
||||
argumentsString.append("\n```\n");
|
||||
for (int i = 0; i != argumentsArray.length; i++) {
|
||||
argumentsString.append(getSingleLineLogStringEntry("Arg " + (i + 1),
|
||||
DataUtils.getTruncatedCommandOutput(argumentsArray[i], DataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, true, false, true),
|
||||
argumentsString.append(Logger.getSingleLineLogStringEntry("Arg " + (i + 1),
|
||||
DataUtils.getTruncatedCommandOutput(argumentsArray[i], Logger.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, true, false, true),
|
||||
"-")).append("`\n");
|
||||
}
|
||||
argumentsString.append("```");
|
||||
@@ -488,23 +488,6 @@ public class ExecutionCommand {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getSingleLineLogStringEntry(String label, Object object, String def) {
|
||||
if (object != null)
|
||||
return label + ": `" + object + "`";
|
||||
else
|
||||
return label + ": " + def;
|
||||
}
|
||||
|
||||
public static String getMultiLineLogStringEntry( String label, Object object,String def) {
|
||||
if (object != null)
|
||||
return label + ":\n```\n" + object + "\n```\n";
|
||||
else
|
||||
return label + ": " + def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public synchronized boolean setState(ExecutionState newState) {
|
||||
// The state transition cannot go back or change if already at {@link ExecutionState#SUCCESS}
|
||||
if(newState.getValue() < currentState.getValue() || currentState == ExecutionState.SUCCESS) {
|
||||
|
@@ -9,7 +9,6 @@ import java.util.regex.Pattern;
|
||||
public class DataUtils {
|
||||
|
||||
public static final int TRANSACTION_SIZE_LIMIT_IN_BYTES = 100 * 1024; // 100KB
|
||||
public static final int LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES = 4 * 1024; // 4KB
|
||||
|
||||
public static String getTruncatedCommandOutput(String text, int maxLength, boolean fromEnd, boolean onNewline, boolean addPrefix) {
|
||||
if(text == null) return null;
|
||||
|
@@ -25,9 +25,12 @@ public class Logger {
|
||||
public static final int LOG_LEVEL_VERBOSE = 3; // start logging verbose messages
|
||||
|
||||
public static final int DEFAULT_LOG_LEVEL = LOG_LEVEL_NORMAL;
|
||||
|
||||
private static int CURRENT_LOG_LEVEL = DEFAULT_LOG_LEVEL;
|
||||
|
||||
public static final int LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES = 4 * 1024; // 4KB
|
||||
|
||||
|
||||
|
||||
static public void logMesssage(int logLevel, String tag, String message) {
|
||||
if(logLevel == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
|
||||
Log.e(getFullTag(tag), message);
|
||||
@@ -230,6 +233,20 @@ public class Logger {
|
||||
|
||||
return stackTracesString.toString();
|
||||
}
|
||||
|
||||
public static String getSingleLineLogStringEntry(String label, Object object, String def) {
|
||||
if (object != null)
|
||||
return label + ": `" + object + "`";
|
||||
else
|
||||
return label + ": " + def;
|
||||
}
|
||||
|
||||
public static String getMultiLineLogStringEntry(String label, Object object, String def) {
|
||||
if (object != null)
|
||||
return label + ":\n```\n" + object + "\n```\n";
|
||||
else
|
||||
return label + ": " + def;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user