Improve Logger

This commit is contained in:
topjohnwu 2017-05-31 17:43:55 +08:00
parent 29096eb5d7
commit 27879c3f01

View File

@ -4,37 +4,30 @@ import android.util.Log;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import java.util.Locale;
public class Logger { public class Logger {
public static final String TAG = "Magisk"; public static final String MAIN_TAG = "Magisk";
public static final String DEBUG_TAG = "MagiskManager";
public static void debug(String msg) { public static void debug(String fmt, Object... args) {
Log.d(TAG, "DEBUG: " + msg); Log.d(DEBUG_TAG, "DEBUG: " + String.format(Locale.US, fmt, args));
} }
public static void error(String msg) { public static void error(String fmt, Object... args) {
Log.e(TAG, "MANAGERERROR: " + msg); Log.e(MAIN_TAG, "MANAGERERROR: " + String.format(Locale.US, fmt, args));
} }
public static void dev(String msg, Object... args) { public static void dev(String fmt, Object... args) {
if (MagiskManager.devLogging) { if (MagiskManager.devLogging) {
if (args.length == 1 && args[0] instanceof Throwable) { Log.d(DEBUG_TAG, String.format(Locale.US, fmt, args));
Log.d(TAG, "MANAGER: " + msg, (Throwable) args[0]);
} else {
Log.d(TAG, "MANAGER: " + String.format(msg, args));
}
} }
} }
public static void dev(String msg) { public static void shell(boolean root, String fmt, Object... args) {
if (MagiskManager.devLogging) {
Log.d(TAG, "MANAGER: " + msg);
}
}
public static void shell(boolean root, String msg) {
if (MagiskManager.shellLogging) { if (MagiskManager.shellLogging) {
Log.d(TAG, (root ? "MANAGERSU " : "MANAGERSH ") + msg); Log.d(DEBUG_TAG, (root ? "MANAGERSU: " : "MANAGERSH: ") + String.format(Locale.US, fmt, args));
} }
} }
} }