2016-05-03 24 views
12

Quindi sto cercando di trovare un bug elusivo in una base di codice di grandi dimensioni. Come tale, ho inserito molta registrazione nella mia app. Sono abbastanza fortunato da avere più tester che lavorano su questo. Tuttavia, ho trovato che mancano molti dei miei log di log. Sono nascosti come "chiacchieroni". Per esempioPossiamo disattivare "chatty" in logcat?

1799 12017 I logd: uid=10007 chatty comm=Binder_B, expire 4 lines

ho trovato qualche cenno di utilizzare il comando adb

adb logcat -p

ma non riesco a trovare alcuna documentazione per il -p. Ho anche scoperto che con molti dispositivi (forse tutti i dispositivi su Marshmallow) questo non è supportato.

Oltre ad avere il dispositivo collegato ad Android Studio/Eclipse, esiste un modo per interrompere "chatty" dal nascondere i miei registri?

+0

potrebbe essere qualche informazione interessante sui temi M qui: https://github.com/JakeWharton/pidcat/issues/102 – stkent

+0

avevo visto questo, ma non era sicuro di cosa fare di esso. Significa che l'equivalente Marshmallow di 'adb logcat -p' è ' adb logcat -v brief | pidcat' ? – TheUmpteenth

+0

'pidcat' non è rilevante qui - è un wrapper su logcat che rende l'output più facile da leggere - ma da qualche parte nella loro base di codice hanno dovuto affrontare un cambiamento nel comportamento di logcat introdotto in Android M. Se riesci a trovare quel problema/cambiarlo potrebbe dare qualche idea su diversi comportamenti su M/pre-M. – stkent

risposta

0

Ho creato il mio debugger e debug_mode & DEBUG_WITH_STACKTRACE_MODE sono abilitati vero in build.gradle di debug {} e falso bydefault

public class AppLoger { 
     public static boolean DEBUG_MODE = BuildConfig.LOG_DEBUG_MODE; 
public static boolean DEBUG_WITH_STACKTRACE_MODE =  BuildConfig.LOG_DEBUG_WITH_STACKTRACE_MODE; 

/** 
* @param cls  Class<T> 
* @param message String 
* @author Android Lead 
*/ 
public static <T> void logInfo(Class<T> cls, String message) { 
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) { 
     String tag = cls.getName(); 
     Log.i(tag, "-----"); 
     Log.i(tag, LogType.INFO + ": " + message); 
     if (DEBUG_WITH_STACKTRACE_MODE) { 
      Log.i(tag, getStackTrace()); 
     } 
    } 
} 

/** 
* @param cls  Class<T> 
* @param message String 
* @author Android Lead 
*/ 
public static <T> void logWarning(Class<T> cls, String message) { 
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) { 
     String tag = cls.getName(); 
     Log.w(tag, "-----"); 
     Log.w(tag, LogType.WARNING + ": " + message); 

     if (DEBUG_WITH_STACKTRACE_MODE) { 
      Log.w(tag, getStackTrace()); 
     } 
    } 
} 

/** 
* @param cls  Class<T> 
* @param message String 
* @author Android Lead 
*/ 
public static <T> void logError(Class<T> cls, String message) { 
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) { 
     String tag = cls.getName(); 
     Log.e(tag, "-----"); 
     Log.e(tag, LogType.ERROR + ": " + message); 

     if (DEBUG_WITH_STACKTRACE_MODE) { 
      Log.e(tag, getStackTrace()); 
     } 
    } 
} 

/** 
* @param cls  Class<T> 
* @param message String 
* @author Android Lead 
*/ 
public static <T> void logError(Class<T> cls, String message, Throwable e) { 
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) { 
     String tag = cls.getName(); 
     Log.e(tag, "-----"); 
     Log.e(tag, LogType.ERROR + ": " + message, e); 

     if (DEBUG_WITH_STACKTRACE_MODE) { 
      Log.e(tag, getStackTrace()); 
     } 
    } 
} 

/** 
* @param tag String 
* @param msg String/JSON/ArrayList 
* @author Android Lead 
*/ 
public static void e(String tag, Object msg) { 
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) 
     Log.e(tag, "" + msg); 
} 

/** 
* @param tag String 
* @param msg String/JSON/ArrayList 
* @author Android Lead 
*/ 
public static void i(String tag, Object msg) { 
    if (DEBUG_MODE || DEBUG_WITH_STACKTRACE_MODE) 
     Log.i(tag, "" + msg); 
} 

/** 
* @author Android Lead 
*/ 
private static String getStackTrace() { 
    StringWriter sw = new StringWriter(); 
    PrintWriter pw = new PrintWriter(sw); 
    new Throwable().printStackTrace(pw); 
    return sw.toString(); 
} 

private enum LogType { 
    INFO, WARNING, ERROR 
} 
} 
+3

Questo è interessante, ma non sono sicuro di come risolva il mio problema. – TheUmpteenth