Site icon Howtodoandroid

InAppLogger – Logger For Android Application

InAppLogger poster

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

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' } } }
Code language: JavaScript (javascript)

Step 2. Add the dependency

dependencies { implementation 'com.github.velmurugan-murugesan:InAppLogger:1.4' }
Code language: JavaScript (javascript)

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() } }
Code language: JavaScript (javascript)

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" />
Code language: HTML, XML (xml)

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")
Code language: JavaScript (javascript)
Log Info

Adding Warning Log

logger = InAppLogger.loggerInstance!! logger.w("warring Message added")
Code language: JavaScript (javascript)
Log Warning

Adding Error Log

logger = InAppLogger.loggerInstance!! logger.e("error Message added")
Code language: JavaScript (javascript)
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!! }
Code language: PHP (php)
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,

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() }
Code language: JavaScript (javascript)

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

Exit mobile version