I need to log exceptions in my android application. Is there way to log exception so, that i can diagrammatically read this logs and send it to server or somethig like that?
-
possible duplicate of [How do I obtain crash-data from my Android application?](http://stackoverflow.com/questions/601503/how-do-i-obtain-crash-data-from-my-android-application) – Robby Pond Feb 24 '11 at 15:06
3 Answers
I can see a few different situations here:
A: If you're talking about the development process, exceptions can be viewed in LogCat (for example, in the Debug perspective) by clicking on the Error filter.
B: If you're talking about crashes in production apps, stack traces are reported to Google and can be viewed in the Android Market Developer Console.
C: Otherwise, if you want to log and submit an exception that you are catching (and therefore not allowing to crash the activity), then check out the logging class in How do I obtain crash-data from my Android application?
-
Where I can read about Android Market Developer Console? I'd like to know, how does it work – earsonheart Mar 30 '11 at 09:17
-
There's not much to it. You can check it out at http://market.android.com/publish – Matthew Mar 30 '11 at 14:59
Try to use Android Logger - it is the easiest implementation of SLF4J API:
android-logger.properties:
root=ERROR:MyApplication
logger.com.example.ui=DEBUG:MyApplication-UI
MainActivity.java:
package com.example.ui;
import com.noveogroup.android.log.Logger;
import com.noveogroup.android.log.LoggerManager;
public class MainActivity extends Activity {
private static final Logger logger = LoggerManager.getLogger();
private void foo(int value) {
logger.i("entered MainActivity::foo value=%d", value);
try {
// some code
} catch(IOException e) {
logger.e("I/O error occurred", e);
}
}
}
LogCat Output:
I/MyApplication-UI: entered MainActivity::foo value=10
E/MyApplication-UI: I/O error occurred

- 111
- 1
- 3
-
1I tried this and I always get "Logger configuration file is empty. Default configuration will be used" and the Logger does not use the tags I set in the properties-file. I put the android.logger-properties in the src folder, as the documentation says. Using android studio. Any idea why this is happening? – Micky Feb 26 '14 at 11:43
C: Otherwise, if you want to log and submit an exception that you are catching (and therefore not allowing to crash the activity), then check out the logging class in How do I obtain crash-data from my Android application?
Instead of using Android logging class, android-logging-log4j can be used to log exception stack traces.
Logging exception stack traces in Android using slf4j api
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ExampleLog4JOverSLF4J {
private final Logger log = LoggerFactory.getLogger(ExampleLog4JOverSLF4J.class);
public void myMethod() {
try {
// invoke code throwing an exception
}
catch(Exception e) {
log.error("An error occured...", e);
// recover or what ever
}
}
}
Logging exception stack traces in Android using log4j api
import org.apache.log4j.Logger;
public class ExampleLog4J {
private final Logger log = Logger.getLogger(LogConfiguratorTest.class);
public void myMethod() {
try {
// invoke code throwing an exception
}
catch(Exception e) {
log.error("An error occured...", e);
// recover or what ever
}
}
}

- 213
- 2
- 6