Quick Start Guide
Before going ahead : If you haven't yet added library to your build.gradle
file, please refer the Implementation Guide.
Start by initialisation.
Open the application class and add this to it.
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.
<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()
Last updated