Friday 9 March 2018

Know Android Logs Analysis

Hello Guys !!! Hope you all doing well !!!
Today I am going to discuss a very hot topic in Android Development life cycle and it is 

Logs Analysis.
As an Android developer, all of you know Logs analysis is a phase of development and we encounter it time to time.
But Log Analysis is main challenging thing for code maintainer or Support Engineer. 
Once Any Android product launched in market and customer start using it. Then real scenario bugs/issue start coming and it is main Job for Support Engineer/Project maintenance engineer to analysed the Bug/issue with provided set of logs. 
                        All we know “How It is challenging”.
So today I am going to shed some light on it. First We start with type of Log available on Android Eco-system :- 
  • Application Log 
  • System Log
  • Event Log
  • Radio Log
Android logging system consists of:
  • a kernel driver and kernel buffers for storing log messages 
  • C, C++ and Java classes for making log entries and accessing the log messages 
  • Logcat (a standalone program for viewing log messages )
  • DDMS (ability to view and filter the log messages from the host machine)
Android Log Buffer/container
  • main - the main application log 
  • events - for system event information 
  • radio - for radio and phone-related information 
  • system - a log for low-level system messages and debugging
overview of  Android logging System (image by Tetsuyuki Kobabayshi, of Kyoto Microcomputer Co.)





















What Log message contains:-
Each message in the log consists of 
  • A tag indicating the part of the system or application that the message came from
  • A timestamp (at what time this message came)
  • The message log level (or priority of the event represented by the message) and 
  • The log message itself(detail description of error or exception or information etc)
What Each Log Type Contains:-
1. Application log
  • use android.util.Log class methods  to write messages of different priority into the log
  • Java classes declare their tag statically as a string, which they pass to the log method
  • The log method used indicates the message "severity" (or log level)
  • Messages can be filtered by tag or priority when the logs are processed by retrieval tools (logcat)
2. System log 
  • Use the android.util.Slog class to write message with different priority with its associated messages
  • Many Android framework classes utilize the system log to keep their messages separate from (possibly noisy) application log messages
  • A formatted message is delivered through the C/C++ library down to the kernel driver, which stores the message in the appropriate buffer(system buffer)
3. Event log
  • Event logs messages are created using android.util.EventLog class, which create binary-formatted log messages. 
  • Log entries consist of binary tag codes, followed by binary parameters. 
  • The message tag codes are stored on the system at: /system/etc/event-log-tags
  • Each message has the string for the log message, as well as codes indicating the values associated with (stored with) that entry.
4. Radio log
  • Used for radio and phone(modem) related information
  • Log entries consist of binary tags code and message for Network info
  • Logging system automatically routes messages with specific tags into the radio buffer
Log format on Android
below is common log format in android
tv_sec   tv_nsec     priority     pid    tid     tag     messageLen       Message
tag: log tag
tv_sec & tv_nsec: the timestamp of the log messages
pid: the process id of where log messages come from
tid: the thread id
Priority value is one of the following character values, ordered from lowest to highest priority:
V — Verbose (lowest priority)*
D — Debug*
I — Info*
W — Warning*
E — Error*
F — Fatal*
S — Silent (highest priority, on which nothing is ever printed)


Log-File locations
There are several directories where logs (including those from crashes) stores and it are not standardized(i.e. some may be ROM-specific). I am putting some of common here.
  • /data/anr : Dalvik writes stack traces here on ANR, i.e. "Application Not Responding" aka "Force-Close"
  • /data/dontpanic : contains some crash logs including traces
  • /data/kernelpanics :- Stores "kernel panic" related logs
  • /data/tombstones :- may hold several tombstone_nn files (nn is a number from 0 to 10 and after 10 again repeat it)
'Log' command line tool
To capture Logs from the android devices/emulator Below is the some command line tool. In real life project there are log capture application/tool used to capture the logs on user device and shared it back to Developer/maintainer for analysis .
  • adb logcat (shows all type logs for current android system
  • adb logcat -v threadtime (it will include date and time) 
  • adb logcat -v threadtime > logfile.txt (Store logs in logfile.txt) 
Useful filter patterns
You can use below filter in your adb command to filter logs. You can also use this filter to search your logs file(logs provided by user device). 
  • adb logcat -f <output_file>  Save all logs into a file 
  • adb logcat "*:E"  Get all errors and fatals
  • adb logcat | grep -i "foo.example." #get all logs related to “foo.example.*” tagname
  • adb logcat "application_or_tag_name:*" "*:S"  Get all logs by application name 
  • adb logcat -b events "gsm_service_state_change" "*:S"  Get all GSM state changes 
  • adb logcat -b radio Get all Radio events 
Log Analysis 
Till now we get all the fundamental exposure of Android Logging System. Now the time to analyse the logs coming from your application or end user. Here we can divide log analysis in two part
  1. Debug Log :- logs file coming during development and testing phase
  2. Production Log:- Logs file coming directly from end user. 
So guess which one  is difficult Production one Right?  So what is the best approach to debug and get the desire info from the captured logs.  As I discuss above, We can do it  by using 
So in the last Android log analysis is a continuous learning and utilizing your experience process. Personally I analysed logs via relevant filter and tool with my past experience. 
But one thing is good Every android analysis (end user issue/bug log) gives you a new learning and experience. So keep it doing and enjoy your life as a coder and maintainer of android system๐Ÿ˜Ž๐Ÿ˜Ž๐Ÿ˜Ž

Please put your comments in comment box. It will energize me a lot. 
Thanks
Saurabh
Happy Coding!!!!

51 comments:

  1. Android Logs Analysis is a crucial aspect of Android development. Very helpful for all level of developers in Android Mobile App Development. These free self help blogs are so greatly appreciated!

    Look around Devolve for your app development needs or suggestion.

    ReplyDelete
  2. This will be very useful blog for Android App Developers. Every developers should have a knowledge about this and Android logs analysis is much important thing while developing an Android Apps.

    Jeevitha from Way2Smile (Android App Development Company in Chennai).

    ReplyDelete
  3. Your blog has chock-a-block of useful information. I liked your blog's content as well as its look. In my opinion, this is a perfect blog in all aspects. how to install twrp on Android

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our. website

    ReplyDelete
  6. Very Good information . Keep posting

    ReplyDelete
  7. Love to read it,Waiting For More new Update and I Already Read your Recent Post its Great Thanks. google my business

    ReplyDelete
  8. Going to graduate school was a positive decision for me. I enjoyed the coursework, the presentations, the fellow students, and the professors. And since my company reimbursed 100% of the tuition, the only cost that I had to pay on my own was for books and supplies. Otherwise, I received a free master’s degree. All that I had to invest was my time. Tubidy APK 2020 Download Free

    ReplyDelete
  9. The designers need to focus on various adaptations of Android to make the application famous and beneficial in the short run. Bulk SMS Service Provider in Sharjah UAE

    ReplyDelete
  10. This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back. accounting system Malaysia

    ReplyDelete
  11. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article
    Advanced MLM Software Jaipur

    ReplyDelete
  12. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
    Advanced MLM Software Jaipur

    ReplyDelete
  13. this post is so good.I am read your article.thanks for sharing..Smart contract development company mirzapur

    ReplyDelete
  14. Great Post…This Article is very unique. Thanks for sharing and very informative!!!MLM Software Development Company Mumbai

    ReplyDelete
  15. I wanted to thank you a lot more for this amazing web-site you have created here. It truly is full of useful tips for those who are genuinely interested in this subject, specifically this very post. Your all actually sweet plus thoughtful of others as well as reading your site posts is a wonderful delight in my experience. And what a generous reward! Mary and I will certainly have fun making use of your guidelines in what we must do in a few weeks. Our checklist is a mile long which means that your tips might be put to great use. buy bank logs with email access

    ReplyDelete
  16. Great job fsexologist Doctorsor publishing such a beneficial blog.

    ReplyDelete
  17. Great Article!!!Thanks for sharing and very Informative Article…gupt rog doctors in allahabad

    ReplyDelete
  18. this post is so good.I am read your article.thanks for sharing..Best Sexologist in Prayagraj

    ReplyDelete
  19. this post is so good.I am read your article.thanks for sharing.sexologist Doctors

    ReplyDelete
  20. This post is really nice thanks for it keep posting.Sexologist in Allahabad

    ReplyDelete
  21. I really really love it. It's so good and so awesome. I am just amazed.
    gupt rog in Allahabad

    ReplyDelete
  22. This post is really nice thanks for it keep posting.sexologist Doctors

    ReplyDelete
  23. i really try these steps its very helpful to me , thanks for this amazing blog .sexologist Doctors

    ReplyDelete
  24. Thanks for sharing!!!
    Your blog is very nice and we hope you are providing more information in future times.
    Venetian Mirror
    Wine Glass
    Bathroom Mirror

    ReplyDelete
  25. . Very interesting information I like this blog very much so much superb information. Call center software | Best call center software

    ReplyDelete
  26. Thanks for sharing, information is really useful, keep posting.
    Unified Communications

    ReplyDelete
  27. I appreciate your website. Its really very help full. Thanks for sharing the great information
    app development company
    ecommerce web development company

    ReplyDelete
  28. Excellent post. I certainly appreciate this website. Keep writing !!!!!!!!! top 10 sexologist doctors in Allahabad ayurvedic clinic

    ReplyDelete
  29. Thank you a lot for this post that was very interesting. You can visit Also smart contract mlm software

    ReplyDelete
  30. Excellent blog with useful concept. Really I feel very happy to see this informative blog, Thanks for sharing such a nice blog. top Best Sexologist Clinic in Allahabad Arth ayurvedic clinic

    ReplyDelete
  31. This comment has been removed by the author.

    ReplyDelete

Build a Custom Kernel Module for Android

Hi Guys!!!Hope you are doing well !!!. Today I will describe how you can write a custom kernel module(Hello world) for Android and load it a...