6

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.

Dmytro
  • 2,200
  • 3
  • 20
  • 32

5 Answers5

5

Look at Android Log Collector.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
4

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);
 }
}
Dmytro
  • 2,200
  • 3
  • 20
  • 32
3

Microlog - A logging framework for Java ME and Android inspired by Log4j.

(c) http://en.wikipedia.org/wiki/Log4j

"Using Microlog for Logging on Android & Viewing the Logs in the Emulator" by Johan Karlsson

Newsflash! Microlog for Android - microlog4android

Helpa
  • 709
  • 1
  • 12
  • 23
1

I am using the application aLogCat downloaded free from android market.

Works very good.

dparnas
  • 4,090
  • 4
  • 33
  • 52
0

Logging frameworks like log4j already provide features like logging to a file. Using android-logging-log4j it is possible to log to a rotating log file and to logcat. Also see log4j support in Android.

Community
  • 1
  • 1
Rolf Kulemann
  • 213
  • 2
  • 6