A client-side Android library to interact with Datadog.
dependencies {
implementation("com.datadoghq:dd-sdk-android:x.x.x")
}
Before you can use the SDK, you need to setup the library with your application
context and your API token. You can create a token from the Integrations > API
in Datadog. Make sure you create a key of type Client Token
.
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
Datadog.initialize(this, BuildConfig.DD_CLIENT_TOKEN)
}
}
If you're targetting our Europe servers, you can initialize the library like this:
class SampleApplication : Application() {
override fun onCreate() {
super.onCreate()
Datadog.initialize(this, BuildConfig.DD_CLIENT_TOKEN, Datadog.DATADOG_EU)
}
}
You can create a Logger
instance using the dedicated builder, as follow:
logger = Logger.Builder()
.setNetworkInfoEnabled(true)
.setServiceName("com.example.app.android")
.setLogcatLogsEnabled(true)
.setDatadogLogsEnabled(true)
.setLoggerName("name")
.build();
You can then send logs with the following methods, mimicking the ones available in the Android Framework:
logger.d("A debug message.")
logger.i("Some relevant information ?")
logger.w("An important warning…")
logger.e("An error was met!")
logger.wtf("What a Terrible Failure!")
If you caught an exception and want to log it with a message, you can do so as follow:
try {
doSomething()
} catch (e : IOException) {
logger.e("Error while doing something", e)
}
Note: All log level methods can have a throwable attached to them.
Pull requests are welcome, but please open an issue first to discuss what you would like to change. For more information, read the Contributing Guide.