Android Base Debug & Log

What is ADB? What is LogCat? Filter Log Results Full Log Example Download Full Example

What is debug?

Debugging programs is the process of identifying and correcting programming errors. In English it is known as debugging, it resembles the elimination of bugs (bugs), a way in which the programming errors are known informally. It is said that the term bug comes from the era of thermionic valve computers, in which the problems were generated by insects who were attracted by the lights and spoiled the equipment.

Android Debug Logs Base Tutorial

Android Debug Logs


What is ADB?

The default way to solve it in Android is with Adb Debug Brigde.
Basically Android Debug Bridge (ADB) is a versatile command line tool that lets you communicate with an instance of an emulator or a connected Android device. This tool provides different actions on devices, such as installing and debugging apps, and provides access to a Unix shell that you can use to run multiple commands on an emulator or a connected device.

Enable ADB Debugging On Your Device

To use ADB with a device connected via USB, you must enable USB debugging in the system settings of the device, which is located in Developer options.

In Android 4.2 and later, the Developer options screen is hidden by default. To view it, go to Settings> About phone and press Build number seven times. When you return to the previous screen, you will see Developer options at the bottom.

Configure Generation Variants

You can configure build variants to create different versions of the application from a single project and how to properly manage their dependencies and sign configurations.

Each build variant represents a different version of the application you can create. For example, you may want to create a version of your free application, with a limited set of content and another payment version that includes more. You can also create different versions of your application that target different devices, based on API level or other device variations. However, if you want to create different versions based on the ABI device or screen density, instead of building multiple APKs. And the general example is build and distinguish between versions of realization or debug.

The idea behind is create code sets to control exactly what files Gradle compiles and packages for specific build types, it’s more for avanced level, for more info show links at the bottom.

What is Logging?

Recording to the sequential recording in a file or in a database of all events (events or actions) that affect a particular process (application, activity of a computer network, etc.). In this way it constitutes an evidence of the behavior of the system.

So the Loggin systems is also a way to debug the app, and persistence the behavior and activity.

What is LogCat?

Logcat command line tool

Logcat is a command line tool that flies a log of system messages, includes stack traces, system error cases and messages that write to your application with the registry class.

Logcat is also that is generally know the log system of Android Platform.

Command-line syntax

You can run logcat as an ADB command or directly on a shell request from your emulator or connected device. To view logging results using ADB, go to the platform-tools / directory of your SDK and run the following:

$ Adb logcat
You can create a shell connection with a device and execute the following:

$ Adb shell
# Logcat

Registration From Source Code

The Log class allows you to create log entries that appear in the logcat tool by code.

Common registration methods include the following:

Where the first string field is a TAG usually define a constant with the class definition (and other suffix of the method or component) the second is a Content. The TAG has a max size of 32 chars and other string is the place for the content to trace.

For example, using the following call to trace on Debug Level:

The logcat results approximate the following (watch (D/) for Debug Level):

Filter Records Results

Android registration messages have a tag and a priority attached to them.

The label of a log message is a short string indicating the system component where the message originates (for example, “view” for the view system).

The priority is one of the following character values ??sorted from lowest to highest priority:

     V:  (Verbose) Detail (lowest priority)
     D:  Debugging
     I:  Information
     W:  Warning
     E:  Error
     F:  Fatal
     S:  Silence (highest priority in which nothing is ever printed)

    Remember that a filter by level show from that level to higest priority, e.g for level V show all levels, and for I show I, W, E and F.

    Also is very importat the search filter textbox, in this place you can write somethig to look up on all logcat content, it’s usually a perfect place to locate the static TAG used when call the log method.


    Full Log Example

    It teaches us how to show traces of different levels and then how to exploit it to visualize them from the IDE of Android Studio and from a command shell. You can see the executions in the video area. We have taken the example of persistence from the previous lesson and added the following traces:

    At the moment of pressing the persistenceOnClick action is invoked, we can see the  Log.e (validations errors) and 

    Log.d (debug information). Also for each case, e.g. when saving preferences we are tracing  on information level Log.i(TAG , “persistenceOnClick: Saving Preferences…).


    In this case we are tracing debug information about when permissions are granted or when is necessary request to user, all at Debug level.


    And here the handler for get control of how went the requested permissions, we are tracing info when all is right and error in when not.



    Video Debug And Visualize

    Next video show how we can easily from Android Studio start to debug the app, click Debug in the toolbar. Android Studio builds an APK, signs it with a debug key, installs it on your selected device, then runs it and opens the Debug window.
    Show how break point works, debug step by step progress and view expressions. You have it!.

    Functionally we will debug the input data validation method to verify that the user field, age are not empty and age is a number. Let’s go see it!.


    Take Screenshots & Videos

    Android Studio lets you take a screenshot or record a short video of the device screen while your app is running.

    The screenshots and videos are useful as promotional material for your app, and you can also associate them with bug reports that you submit to your development team.

    To take a screenshot of your app: Start your app as described in Run your application in debug mode. Click on Android Monitor. Click on Screen Capture on the left. Optional: To add a device frame around your screenshot, click Frame screenshot. Click Save.

    To record a video from your app (only from real devices and some emulators):

    1. Start your app as described in Run your application in debug mode.
    2. Click on Android Monitor.
    3. Click on Screen Record on the left.
    4. Click Start Recording.
    5. Interact with your app.
    6. Click Stop Recording.
    7. Enter a file name for the recording and click OK.

    Video Logging Shows On Android Monitor

    The video logging shows how when we are acting with the different options of the demo the app are showing the traces of different levels.

    First we have traces of error related to the validation of input data,  then we have informative And debugging.

    At the verbose level, the following information also appears.


    Video Logging Shows By ADB Command

    In this case access the traces median command ADB Logcat.

    We can see all the traces filter by component and by trace level.


    Let’s go there.



    Debugging work fluence on Android Studio, evaluate expressions and navigate bettween code is easy and fast.

    Traces and logging in diferentes levels is always a best practices to debug and improve our app. Remember always control and trace conflict errors.

    Is always useful take captures or video for our apps.

    Recording video from your app only work from real devices and some emulators.

    Remember that a filter by level show from that level to higest priority, e.g for level V show all levels, and for I show I, W, E and F.

    Also is very importat the search filter textbox, in this place you can write somethig to look up on all logcat content, it’s usually a perfect place to locate the static TAG used when call the log method.


    Download Full Example


    All Downloads

    git clone

    Info Links

    Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.



    Leave a Reply

    Social media & sharing icons powered by UltimatelySocial