How to generate Log file in Android Studio?

2 votes
235 views
Anonymous User asked 12-Jan-2018 in Technology by Anonymous User
edited 12-Jan-2018 by Tarun-Gautam

How to generate Log file in Android Studio?

1 Answer

0 votes
Prateek sharma answered 12-Jan-2018 by Prateek sharma

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" />



TarunGautam commented 19-Jan-2018 by TarunGautam
Thanks for your answer!
       0