0

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?

1

3 Answers 3

2

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Where I can read about Android Market Developer Console? I'd like to know, how does it work
There's not much to it. You can check it out at market.android.com/publish
1

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 } } } 

Comments

1

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 

1 Comment

I 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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.