How to generate Log file in Android Studio?

Asked 12-Jan-2018
Updated 12-Jan-2018
Viewed 740 times

1 Answer


0

In order to generate the log file, you need to write the following code

  1. You need to add the following static variable in your MainActivity: 

private static final Logger logger = LoggerFactory.getLogger();

2. Edit the onCreate() method of the MainActivity:

PropertyConfigurator.getConfigurator(this).configure();

3. Create a file microlog.properties and store it in assets directory of your application

4. Now edit the microlog.properties file with the following code:

microlog.level=DEBUG

microlog.appender=LogCatAppender;FileAppender
microlog.formatter=PatternFormatter
microlog.formatter.PatternFormatter.pattern=%c [%P] %m %T

5. You can add logging statements like this-

logger.debug("M4A");

6. If you want to create the log file for each activity, you need to add a logger object as specified in 1 in each activity.

7. You need to add the following permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />




Comment
Thanks for your answer! - Anonymous User19-Jan-2018