Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging on device to file

How to redirect logging on device to file?

My application is hang on device but works great on emulator - I want to see logging on my device without sdk and its tools.

like image 223
Dmytro Avatar asked Feb 16 '10 13:02

Dmytro


2 Answers

Look at Android Log Collector.

like image 156
CommonsWare Avatar answered Sep 21 '22 22:09

CommonsWare


I found excellent feature of Logcat. It can redirect output to file himself by using simple command parameter "-f ". To use it you can write Logcat wrapper in your application aLogcat like. Obviously I made this :)

For using logcat at android I wrote this code:

Process proc = null;
try {
  proc = Runtime.getRuntime().exec(new String[] { "logcat", <!parametes_here!> });
  mReader = new BufferedReader(new InputStreamReader(proc.getInputStream()), 1024);
  String line;
  while ((line = mReader.readLine()) != null) {
   if (line.length() == 0) {
    continue;
   }
  mHandler.sendMessage(mHandler.obtainMessage(Logcat.MSG_READ_LINE, line));
 }
} catch (IOException e) {
 Log.e(TAG, "Cannot start process", e);
} finally {
  if (mReader != null)
  try {
    mReader.close();
  } catch (IOException e) {
    Log.e(TAG, "Cannot close stream", e);
 }
}
like image 36
Dmytro Avatar answered Sep 21 '22 22:09

Dmytro