Skip to content

Commit

Permalink
Fix Logger function modifier order
Browse files Browse the repository at this point in the history
  • Loading branch information
agnostic-apollo committed Apr 6, 2021
1 parent 38323b1 commit 18b004a
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions app/src/main/java/com/termux/app/utils/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Logger {



static public void logMesssage(int logLevel, String tag, String message) {
public static void logMesssage(int logLevel, String tag, String message) {
if(logLevel == Log.ERROR && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), message);
else if(logLevel == Log.WARN && CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Expand All @@ -46,57 +46,57 @@ else if(logLevel == Log.VERBOSE && CURRENT_LOG_LEVEL >= LOG_LEVEL_VERBOSE)



static public void logError(String tag, String message) {
public static void logError(String tag, String message) {
logMesssage(Log.ERROR, tag, message);
}

static public void logError(String message) {
public static void logError(String message) {
logMesssage(Log.ERROR, DEFAULT_LOG_TAG, message);
}



static public void logWarn(String tag, String message) {
public static void logWarn(String tag, String message) {
logMesssage(Log.WARN, tag, message);
}

static public void logWarn(String message) {
public static void logWarn(String message) {
logMesssage(Log.WARN, DEFAULT_LOG_TAG, message);
}



static public void logInfo(String tag, String message) {
public static void logInfo(String tag, String message) {
logMesssage(Log.INFO, tag, message);
}

static public void logInfo(String message) {
public static void logInfo(String message) {
logMesssage(Log.INFO, DEFAULT_LOG_TAG, message);
}



static public void logDebug(String tag, String message) {
public static void logDebug(String tag, String message) {
logMesssage(Log.DEBUG, tag, message);
}

static public void logDebug(String message) {
public static void logDebug(String message) {
logMesssage(Log.DEBUG, DEFAULT_LOG_TAG, message);
}



static public void logVerbose(String tag, String message) {
public static void logVerbose(String tag, String message) {
logMesssage(Log.VERBOSE, tag, message);
}

static public void logVerbose(String message) {
public static void logVerbose(String message) {
logMesssage(Log.VERBOSE, DEFAULT_LOG_TAG, message);
}



static public void logErrorAndShowToast(Context context, String tag, String message) {
public static void logErrorAndShowToast(Context context, String tag, String message) {
if (context == null) return;

if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL) {
Expand All @@ -105,13 +105,13 @@ static public void logErrorAndShowToast(Context context, String tag, String mess
}
}

static public void logErrorAndShowToast(Context context, String message) {
public static void logErrorAndShowToast(Context context, String message) {
logErrorAndShowToast(context, DEFAULT_LOG_TAG, message);
}



static public void logDebugAndShowToast(Context context, String tag, String message) {
public static void logDebugAndShowToast(Context context, String tag, String message) {
if (context == null) return;

if(CURRENT_LOG_LEVEL >= LOG_LEVEL_DEBUG) {
Expand All @@ -120,35 +120,35 @@ static public void logDebugAndShowToast(Context context, String tag, String mess
}
}

static public void logDebugAndShowToast(Context context, String message) {
public static void logDebugAndShowToast(Context context, String message) {
logDebugAndShowToast(context, DEFAULT_LOG_TAG, message);
}



static public void logStackTraceWithMessage(String tag, String message, Throwable throwable) {
public static void logStackTraceWithMessage(String tag, String message, Throwable throwable) {
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), getMessageAndStackTraceString(message, throwable));
}

static public void logStackTraceWithMessage(String message, Throwable throwable) {
public static void logStackTraceWithMessage(String message, Throwable throwable) {
logStackTraceWithMessage(DEFAULT_LOG_TAG, message, throwable);
}

static public void logStackTrace(String tag, Throwable throwable) {
public static void logStackTrace(String tag, Throwable throwable) {
logStackTraceWithMessage(tag, null, throwable);
}

static public void logStackTrace(Throwable throwable) {
public static void logStackTrace(Throwable throwable) {
logStackTraceWithMessage(DEFAULT_LOG_TAG, null, throwable);
}

static public void logStackTracesWithMessage(String tag, String message, List<Throwable> throwableList) {
public static void logStackTracesWithMessage(String tag, String message, List<Throwable> throwableList) {
if(CURRENT_LOG_LEVEL >= LOG_LEVEL_NORMAL)
Log.e(getFullTag(tag), getMessageAndStackTracesString(message, throwableList));
}

static public String getMessageAndStackTraceString(String message, Throwable throwable) {
public static String getMessageAndStackTraceString(String message, Throwable throwable) {
if(message == null && throwable == null)
return null;
else if(message != null && throwable != null)
Expand All @@ -159,7 +159,7 @@ else if(throwable == null)
return getStackTraceString(throwable);
}

static public String getMessageAndStackTracesString(String message, List<Throwable> throwableList) {
public static String getMessageAndStackTracesString(String message, List<Throwable> throwableList) {
if(message == null && (throwableList == null || throwableList.size() == 0))
return null;
else if(message != null && (throwableList != null && throwableList.size() != 0))
Expand All @@ -170,7 +170,7 @@ else if(throwableList == null || throwableList.size() == 0)
return getStackTracesString(null, getStackTraceStringArray(throwableList));
}

static public String getStackTraceString(Throwable throwable) {
public static String getStackTraceString(Throwable throwable) {
if(throwable == null) return null;

String stackTraceString = null;
Expand All @@ -188,7 +188,8 @@ static public String getStackTraceString(Throwable throwable) {

return stackTraceString;
}
private static String[] getStackTraceStringArray(Throwable throwable) {

public static String[] getStackTraceStringArray(Throwable throwable) {
return getStackTraceStringArray(Collections.singletonList(throwable));
}

Expand All @@ -210,22 +211,28 @@ public static String getStackTracesString(String label, String[] stackTraceStrin
stackTracesString.append(" -");
} else {
for (int i = 0; i != stackTraceStringArray.length; i++) {
stackTracesString.append("\n\nStacktrace ").append(i + 1).append("\n```\n").append(stackTraceStringArray[i]).append("\n```\n");
if(stackTraceStringArray.length > 1)
stackTracesString.append("\n\nStacktrace ").append(i + 1);

stackTracesString.append("\n```\n").append(stackTraceStringArray[i]).append("\n```\n");
}
}

return stackTracesString.toString();
}

public static String getStackTracesMarkdownString(String label, String[] stackTraceStringArray) {
if(label == null) label = "StackTraces:";
if(label == null) label = "StackTraces";
StringBuilder stackTracesString = new StringBuilder("### " + label);

if (stackTraceStringArray == null || stackTraceStringArray.length == 0) {
stackTracesString.append("\n\n`-`");
} else {
for (int i = 0; i != stackTraceStringArray.length; i++) {
stackTracesString.append("\n\n\n#### Stacktrace ").append(i + 1).append("\n\n```\n").append(stackTraceStringArray[i]).append("\n```");
if(stackTraceStringArray.length > 1)
stackTracesString.append("\n\n\n#### Stacktrace ").append(i + 1);

stackTracesString.append("\n\n```\n").append(stackTraceStringArray[i]).append("\n```");
}
}

Expand All @@ -250,7 +257,7 @@ public static String getMultiLineLogStringEntry(String label, Object object, Str



static public void showToast(final Context context, final String toastText, boolean longDuration) {
public static void showToast(final Context context, final String toastText, boolean longDuration) {
if (context == null) return;

new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, toastText, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show());
Expand Down Expand Up @@ -313,7 +320,7 @@ public static int setLogLevel(Context context, int logLevel) {
return CURRENT_LOG_LEVEL;
}

static public String getFullTag(String tag) {
public static String getFullTag(String tag) {
if(DEFAULT_LOG_TAG.equals(tag))
return tag;
else
Expand Down

0 comments on commit 18b004a

Please sign in to comment.