Extienda Android.util.Log para escribir en el archivo

Me gustaría extender la clase android.util.Log para escribir también en un archivo de registro en el almacenamiento interno del dispositivo, preferiblemente también para TAGS específicos.

Actualmente tengo una implementación:

 public class CustomLogger{ private final static Logger fileLog = Logger.getLogger(MainActivity.class); private Context context; public CustomLogger(Context c){ this.context = c; final LogConfigurator logConfigurator = new LogConfigurator(); logConfigurator.setFileName(context.getFilesDir() + File.separator + "myApp.log"); logConfigurator.setRootLevel(Level.DEBUG); logConfigurator.setLevel("org.apache", Level.ERROR); logConfigurator.configure(); } public void i(String TAG, String message){ // Printing the message to LogCat console Log.i(TAG, message); // Write the log message to the file fileLog.info(TAG+": "+message); } public void d(String TAG, String message){ Log.d(TAG, message); fileLog.debug(TAG+": "+message); } } 

Como puede ver este registrador personalizado registra tanto en un archivo de registro en el almacenamiento interno (mediante la biblioteca android-logging-log4j ) como a través de la clase android.util.Log . Sin embargo, me gustaría que las entradas de registro estándar de la clase android.util.Log en mi archivo de registro, y si es posible sólo ciertas (personalizadas) TAGS .

¿Alguien tiene un ejemplo o algún buen consejo sobre cómo llegar a esto?

Gracias por adelantado

Puede leer log cat de forma programática y almacenar en un archivo de texto o enviarlo donde lo desee.

Abajo es el artículo detallado tengo escritor para el mismo

Leer y almacenar Log-cat mediante programación en Android

Y Para leer el logcat aquí es código de ejemplo

  public class LogTest extends Activity { private StringBuilder log; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { Process process = Runtime.getRuntime().exec("logcat -d"); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(process.getInputStream())); log=new StringBuilder(); String line; while ((line = bufferedReader.readLine()) != null) { log.append(line); } TextView tv = (TextView)findViewById(R.id.textView1); tv.setText(log.toString()); } catch (IOException e) { } //convert log to string final String logString = new String(log.toString()); //create text file in SDCard File sdCard = Environment.getExternalStorageDirectory(); File dir = new File (sdCard.getAbsolutePath() + "/myLogcat"); dir.mkdirs(); File file = new File(dir, "logcat.txt"); try { //to write logcat in text file FileOutputStream fOut = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fOut); // Write the string to the file osw.write(logString); osw.flush(); osw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } 

Así que hay mucho más corto variante

 tratar {
     Final File path = new Archivo (
             Environment.getExternalStorageDirectory (), "DBO_logs5");
     If (! Path.exists ()) {
         Path.mkdir ();
     }
     Runtime.getRuntime (). Exec (
             "Logcat -d -f" + path + File.separator
                     + "Dbo_logcat"
                     + ".txt");
 } Catch (IOException e) {
     E.printStackTrace ();
 }
  • Android Runtime Logcat solo obtiene la instancia actual
  • ¿Por qué LogCat muestra todos los elementos como advertencias (naranja)?
  • ¿Hay un límite de longitud para String en Android?
  • Cómo mostrar sólo mensaje de registro (ocultar hora, pid etc.) en Android Studio
  • Huawei, logcat no mostrar el registro de mi aplicación?
  • Sería mejor ser explícito si se requiere un buffer de 8k-char.
  • Eclipse Android - Logcat Despejar demasiado rápido
  • ¿Puedo activar la funcionalidad integrada de captura de errores de Android desde mi aplicación?
  • ¿Qué significan estos números en Android Logcat?
  • OnCreateView método se llama cuando? Y ¿Cuántas veces en el ciclo de vida de la actividad?
  • ¿Hay alguna manera de acceder automáticamente a cualquier Log in Logcat por un doble clic?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.