Pulp is a very simple logger tool for android using Kotlin programming language.
- Add the dependency code to your project
implementation "ir.malv.utils:pulp:$version"Or include the pre-release version
- Add this to your gradle repositories
maven { url 'https://dl.bintray.com/mah-d/preview' }implementation "ir.malv.utils:pulp:$version"Pulp.info("TAG", "This is a message")Pulp.info("TAG", "Message, but not enough") {
"ExtraMessage1" to "Message..."
"ExtraMessage2" to "Message..."
// ...
}Note: You can pass an array of tags instead of one:
Pulp.warn(arrayOf("Be careful", "MyApp"), "Message", throwable)Output will be like:
2019-08-01 16:06:40.768 26299-26299/ir.malv.logtest I/Pulp: MainTag:
Tags: [TAG]
Message: Message but not enough
Data:
ExtraMessage1 Message...
ExtraMessage2 Message...
val t = Throwable("Error")
Pulp.error("TAG", "Failed", t) {
"Extra data" to "data"
}Pulp.setMainTag("My APP")Pulp.setLogsEnabled(false)Disabling the logger can also be done using an AndroidManifest meta-data.
<meta-data android:name="pulp_enabled" android:value="false" />Note: To get Pulp extract manifest (since it needs constructor), you need to add this to your Application class:
Pulp.init(this /* context */)When Pulp triggers to print a log, it can be listened using callbacks.
Pulp.addHandler(object: Pulp.LogHandler {
override fun onLog(
level: Pulp.Level,
tags: List<String>,
message: String,
t: Throwable?,
data: Pulp.LogData
) {
// Get the data and do stuff
}
})Note: You can add multiple handlers and all of them will be called when logging.
- Handlers can also be disabled:
Pulp.setHandlerEnabled(enabled = false)Pulp can save logs into it's database and return the in a LiveData stream.
To enable database call:
Pulp.setDatabaseEnabled(true)And because interacting with database needs context, make sure you have called Pulp.init(context), or Pulp.setApplicationContext(context).
And to interact with database using this code:
val savedLogs: LiveData<List<PulpItems>> = Pulp.getSavedLogs(context)
savedLogs.observe(activity, Observer {
// it is List<PulpItem>
})and to clear the logs:
Pulp.clearLogs(context)D: DebugI: InfoW: WarningE: ErrorWTF: Unexpected
When you don't want to send callback or follow the message style of pulp, you can print a simple message.
Pulp.sout("Message") // output: MainTag ### MessageIt will not notify callbacks.
- All config methods can be chained:
Pulp.init(this)
.setMainTag("MyApp")
.setHandlerEnabled(true)
.setLogsEnabled(true)
.setDatabaseEnabled(true)
.addHandler(object : Pulp.LogHandler {
// ...
})