How to generate Log file in Android Studio?

2 votes
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:


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

4. Now edit the file with the following code:


microlog.formatter.PatternFormatter.pattern=%c [%P] %m %T

5. You can add logging statements like this-


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

Anonymous User commented 19-Jan-2018 by Anonymous User
Thanks for your answer!