An Android package usable for HTTP logging and passing analytics to a third-party SDK. Also included is an abstraction class for using Google's Firebase analytics platform.
The main functionality of the logging module is to provide a single source of truth for standardised code logging functionality that makes it simple to switch logging framework if desired.
The three packages have the following functionality:
- The
:api
module contains logger interfaces. - The
:impl
module contains logger implementations and their associated Hilt modules for dependency injection into their constructors. - The
:testdouble
module contains fake logger implementations for testing and their Hilt modules for dependency injection into their constructors.
In your build.gradle.kts
files, for each module (and for each build flavor), add dependencies
needed for example:
// Refer to the uploaded packages for the latest version:
// https://github.com/orgs/govuk-one-login/packages?repo_name=mobile-android-logging
val loggingLibraryVersion: String by rootProject.extra("1.2.3")
// Both `impl` and `testdouble` artifacts provide the `api` module as a gradle `api` dependency.
implementation("uk.gov.logging:logging-impl:$loggingLibraryVersion")
testImplementation("uk.gov.logging:logging-testdouble:$loggingLibraryVersion")
androidTestImplementation("uk.gov.logging:logging-testdouble:$loggingLibraryVersion")
To migrate to using version catalogs, see Gradle Version Catalogs.
In your root ./gradle/libs.versions.toml
file:
[versions]
gov-logging = "1.2.3" # https://github.com/orgs/govuk-one-login/packages?repo_name=mobile-android-logging
[libraries]
uk-gov-logging-api = { module = "uk.gov.logging:logging-api", version.ref = "gov-logging"}
uk-gov-logging-impl = { module = "uk.gov.logging:logging-impl", version.ref = "gov-logging"}
uk-gov-logging-testdouble = { module = "uk.gov.logging:logging-testdouble", version.ref = "gov-logging"}
Then in your build.gradle.kts
files:
// Both `impl` and `testdouble` artifacts provide the `api` module as a gradle `api` dependency.
implementation(libs.uk.gov.logging.impl)
testImplementation(libs.uk.gov.logging.testdouble)
androidTestImplementation(libs.uk.gov.logging.testdouble)
Despite there being usable Hilt modules in the logging
module, these are mainly for
Android Logging. You should also create your own Singleton
scoped Hilt modules to provide the
specific analytics logger implementation that you need, and also to provide the Firebase analytics
implementation. For example:
@InstallIn(SingletonComponent::class)
@Module
object AnalyticsSingletonModule {
@Provides
@Singleton
fun providesAnalyticsLogger(
analyticsLogger: FirebaseAnalyticsLogger
): AnalyticsLogger = MemorisedAnalyticsLogger(analyticsLogger)
}
@InstallIn(SingletonComponent::class)
@Module
class FirebaseSingletonModule {
@Provides
@Singleton
fun providesFirebaseAnalytics(): FirebaseAnalytics = Firebase.analytics
}
The packages can be found at here at Logging Module Packages.
The tags can be found at here at Logging Module Tags.
There has been a breaking change on some of the required parameters. We support both the original and the new GA4. However you will need to import the correct type based on your need.
// GA4 type
import uk.gov.logging.api.analytics.parameters.v2.RequiredParameters
// Original type
import uk.gov.logging.api.analytics.parameters.RequiredParameters
If you need to use both GA4 and the original one in the same file, you will need to import as an alias
import uk.gov.logging.api.analytics.parameters.RequiredParameters
import uk.gov.logging.api.analytics.parameters.v2.RequiredParameters as RequiredParametersV2
Implementation Guide One Login Mobile Application Data Schema V1.0.