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:
- Android OCR utilizando tess-dos un tenedor de tesseract
- No se puede ver la salida de depuración al ejecutar el emulador de Android
- Los datos de Logcat no se muestran en la ficha Registro de DDMS Eclipse
- Android, la ventana de Logcat ha desaparecido
- Leer Logcat mediante programación dentro de la aplicació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
- Android ADB Logcat: etiqueta con dos puntos
- Eliminar Logcat de la perspectiva de Java
- Acceso a LogCat desde Android a través de Python
- Creando la gravedad del juego en Android (continuación)?
- Android Studio: ¿qué está causando los logs de la fuente de alimentación de la batería logcat?
- Android: ¿Puedo ignorar los errores "Vista primaria no es un TextView" y "sendUserActionEvent () mView == null"?
- Android Recycle View LogCat: No se pudo encontrar el método
- Android Logcat está vacío cuando se depura con el dispositivo en android studio
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 (); }
- Confundido acerca de las diferencias de AdMob, Ad Exchange y DFP
- Diferencia real entre TextView y Button