> For the complete documentation index, see [llms.txt](https://adityabavadekar.gitbook.io/pinlog-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adityabavadekar.gitbook.io/pinlog-docs/quick-start-guide.md).

# Quick Start Guide

{% hint style="danger" %}
**Before going ahead :** If you haven't yet added library to your `build.gradle` file, please refer the [Implementation Guide](/pinlog-docs/implementation-guide.md).
{% endhint %}

## Start by initialisation.

> Open the application class and add this to it.

{% hint style="info" %}
**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.
{% endhint %}

{% code title="App.kt" %}

```kotlin
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
    }

}
```

{% endcode %}

Then you need to mention this file in your AndroidManifest.xml like this :&#x20;

The <mark style="color:red;">`android:name=".App"`</mark> line is most important.

{% code title="AndroidManifest.xml" %}

```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>
```

{% endcode %}

#### 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.

```kotlin
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.

```kotlin
//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 :

```kotlin
//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.

```kotlin
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` .

```kotlin
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

```kotlin
PinLog.removeListener(myListener)
```

To remove all listeners at once call this

```kotlin
PinLog.removeAllListeners()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://adityabavadekar.gitbook.io/pinlog-docs/quick-start-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
