InAppLogger – Logger For Android Application

InAppLogger is a very useful app to log your data on the app screen. Normally logs will be shown in android studio Logcat. In some cases like remote debugging, you want to display the logs on the mobile screen to debug. In that case, you can use InAppLogger to display the logs on the device screen.

InAppLogger Demo

You can check the code in the Github repository.

Fatures of InAppLogger

  • Logging Info
  • Logging Error
  • Logging Warnings
  • Logging API
  • Filters Logs
  • Clear Log any time
  • Auto clean log on startup

Installation

To get a Git project into your build:

Step 1. Add the JitPack repository to your build file.

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Step 2. Add the dependency

dependencies {
        implementation 'com.github.velmurugan-murugesan:InAppLogger:1.4'
    }

Usage

To initialize the InAppLogger, You need to add the following line in the oncreate() of the Application class.

override fun onCreate() {
            super.onCreate()
            InAppLogger.initialize(this).apply {
                deleteOldLog()
            }
    }

Add Logging View in your layout file where you want to show the logs.

<com.velmurugan.inapplogger.InAppLogView
            android:id="@+id/tv"
            android:layout_width="match_parent"
            android:layout_height="350dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

To show the logger in the view, you need to attach the view to the logger.

logger = InAppLogger.loggerInstance!!
logger.attachView(v)

Adding Info Log

logger = InAppLogger.loggerInstance!!
logger.i("Info Message added")
Log Info

Adding Warning Log

logger = InAppLogger.loggerInstance!!
logger.w("warring Message added")
Log Warning

Adding Error Log

logger = InAppLogger.loggerInstance!!
logger.e("error Message added")
Log Error

Adding API Log

To enable the API logging, you need to add the LoggingInterceptor in your retrofit configurations.

fun getInstance(context: Context): ApiService {
                if (retrofitService == null) {
                    val retrofit = Retrofit.Builder()
                        .client(
                            OkHttpClient().newBuilder().addInterceptor(InAppLoggerInterceptor())
                                .build()
                        )
                        .baseUrl("https://www.howtodoandroid.com/")
                        .addConverterFactory(GsonConverterFactory.create())
                        .build()
                    retrofitService = retrofit.create(ApiService::class.java)
                }
                return retrofitService!!
            }
Log API

Log Filter

Log filtering option available in the Logger view to filter the log to want to see. For example, you want to see only the API logs you can select the API in the log filter. like that we have,

  • Info Log Filter
  • Warning Log Filter
  • Error Log Filter
  • API Log Filter
Log Filter

deleting Log

By default, InAppLogger won’t delete the logs when launching the app. To enable this you need to call the deleteOldLog() on the initialization of the InAppLogger in the Application class.

InAppLogger.initialize(this).apply {
                deleteOldLog()
            }

Also, you can clear the log at any time using the clear button on the Logger view clear button.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *


Latest Posts