PinLog Docs
  • PinLog Logging Library
  • Implementation Guide
  • Quick Start Guide
  • Exception Handling
  • GitHub
  • Reference
    • Library Reference
      • Methods
Powered by GitBook
On this page
  • Start by initialisation.
  • Logging
  • Getting saved logs
  • Deleting saved logs
  • Listening for new logs
  • Removing listeners

Quick Start Guide

PreviousImplementation GuideNextException Handling

Last updated 2 years ago

Before going ahead : If you haven't yet added library to your build.gradle file, please refer the .

Start by initialisation.

Open the application class and add this to it.

Application class : If you don't know what an application class is, no need to worry. This class gets called before any activity in the app is called. Bellow is an application class called as App you can paste this in your App.kt file.

App.kt
class App : Application() {

    override fun onCreate() {
        super.onCreate()

         PinLog.initialiseDebug(this)//If you are testing your app
         //OR
         PinLog.initialiseRelease(this)//If you are releasing your app
         
         PinLog.setDevLogging(true)//Optional
         PinLog.setBuildConfigClass(BuildConfig::class.java)//Optional
    }

}

Then you need to mention this file in your AndroidManifest.xml like this :

The android:name=".App" line is most important.

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application
        android:name=".App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

You are now done with the application class setup.

Logging

Add this in your MainActivity.kt or any similar file and everything is done. Each time you log a statement it gets saved in PinLog's database.

import com.adityaamolbavadekar.pinlog.extensions.logI
import com.adityaamolbavadekar.pinlog.PinLog

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        
        logI("onCreate was called")
        PinLog.logI("MainActivity","This is a info")
        PinLog.logW("MainActivity","This is a warning")
        PinLog.logE("MainActivity","This is a error")
        PinLog.logD("MainActivity","This is a debug log")

    }

}

Getting saved logs

To get your logs use this line.

//Get stored logs 
PinLog.getAllPinLogsAsStringList() 

//Get strored logs with a limit this returns `List<ApplicationLogModel>`
PinLog.getAllPinLogs(maxLogsLimit = 50)

//Get all stored logs a single string
PinLog.getAllPinLogsAsString()

Deleting saved logs

To delete all the logs use this line :

//Delete stored logs 
PinLogs.deleteAllPinLogs()

Listening for new logs

You can also listen for logs by adding listeners. Max limit for listeners is 5

This listener returns a ApplicationLogModel object.

PinLog.addListener(object : OnLogAddedListener {
     override fun onLogAdded(log: ApplicationLogModel){
          Toast.makeText(context,"A new log was added with id ${log.id}",Toast.LENGHT_SHORT).show()
      }
})

If just want the content of log as a string, you can use this listener instead.

This listener returns a log as String .

PinLog.addListener(object : OnStringLogAddedListener {
     override fun onLogAdded(log: String){
          Toast.makeText(context,"A new log was added which is\n $log",Toast.LENGHT_SHORT).show()
      }
})

Every time you use one of the logging methods the listener is called.

Removing listeners

To remove a previously added Listener call this

PinLog.removeListener(myListener)

To remove all listeners at once call this

PinLog.removeAllListeners()

Implementation Guide