Android SDK (Kotlin)
A native Kotlin SDK for Android applications with automatic batching, background delivery, offline log protection, coroutine support, and SSL pinning.
Offline Log Protection
When the API is unavailable (server maintenance, network errors, or outages), logs are automatically buffered in SharedPreferences and delivered when connectivity is restored. Buffer capacity depends on your plan. No configuration needed — the SDK handles everything transparently.
Installation
Gradle (Kotlin DSL)
// In app/build.gradle.kts
dependencies {
implementation("app.grenlogger:sdk:1.0.0")
}GitHub Packages
Add the repository to your settings.gradle.kts:
dependencyResolutionManagement {
repositories {
maven {
url = uri("https://maven.pkg.github.com/grendowdev/grenlogger-android")
credentials {
username = project.findProperty("gpr.user") as String?
password = project.findProperty("gpr.key") as String?
}
}
}
}Initialization
import app.grenlogger.sdk.GrenLogger
// In Application class
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// Basic initialization
GrenLogger.initialize(
context = this,
apiKey = "your_api_key",
userId = "user-123" // optional, required for remote activation
)
}
}
// Privacy-first: no logs until remote activation
GrenLogger.initialize(
context = this,
apiKey = "your_api_key",
userId = "user-123",
remote = false,
local = true
)Logging Methods
// Debug level
GrenLogger.debug("Fragment created", mapOf("fragment" to "HomeFragment"))
// Info level
GrenLogger.info("User logged in", mapOf("method" to "google"))
// Warning level
GrenLogger.warning("API slow", mapOf("latency" to 3500))
// Error level
GrenLogger.error("Request failed", mapOf("endpoint" to "/users"))
// Error with Throwable
GrenLogger.error("Exception caught", throwable = exception)
// Fatal level (auto-flushes)
GrenLogger.fatal("Critical error", throwable = fatalException)User Management
// Set user ID after login
GrenLogger.setUserId("user-abc123")
// Get current user ID
val userId = GrenLogger.getUserId()
// Clear user ID on logout
GrenLogger.setUserId(null)Control Methods
// Async flush
GrenLogger.flush()
// Refresh config from server (e.g. after push for remote activation)
lifecycleScope.launch {
val success = GrenLogger.sync()
}
// Shutdown (use in Application.onTerminate)
GrenLogger.shutdown()Call sync() when you receive a push notification to fetch the latest configuration immediately (e.g. after remote log activation).
Kotlin Coroutines
The SDK uses Kotlin coroutines internally for async operations:
// All logging is non-blocking
lifecycleScope.launch {
GrenLogger.info("Async operation started")
try {
val result = someAsyncWork()
GrenLogger.info("Operation completed", mapOf("result" to result))
} catch (e: Exception) {
GrenLogger.error("Operation failed", throwable = e)
}
}Activity/Fragment Integration
class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
GrenLogger.debug("HomeFragment created")
binding.submitButton.setOnClickListener {
GrenLogger.info("Submit button clicked", mapOf(
"screen" to "HomeFragment",
"action" to "submit"
))
}
}
override fun onDestroyView() {
GrenLogger.debug("HomeFragment destroyed")
super.onDestroyView()
}
}Java Support
The SDK is fully compatible with Java:
import app.grenlogger.sdk.GrenLogger;
import java.util.HashMap;
import java.util.Map;
// Initialize
GrenLogger.initialize("your_api_key", "your_project_id", "user-123");
// Log with metadata
Map<String, Object> metadata = new HashMap<>();
metadata.put("method", "google");
GrenLogger.info("User logged in", metadata);
// Log error with exception
GrenLogger.error("Request failed", null, exception);ProGuard/R8
Add these rules if using ProGuard/R8:
-keep class app.grenlogger.sdk.** { *; }
-keepclassmembers class app.grenlogger.sdk.** { *; }Requirements
- Android API 21+ (Android 5.0 Lollipop)
- Kotlin 1.8+ or Java 8+
- Gradle 7.0+