This is an annotation processor that will generate an appropriate log tag for Android Log messages
You can use the library with either the Kotlin Compiler Plugin or an Annotation Processor
Note
Currently, this feature is experimental.
The K2 Kotlin IntelliJ plugin supports running third party FIR plugins in the IDE, but this feature is hidden behind a flag.
To enable it, do the following:
- Enable K2 Mode for the Kotlin IntelliJ plugin.
- Open the Registry
- Set the kotlin.k2.only.bundled.compiler.plugins.enabled entry to false.
That support is unstable and subject to change.
Apply the compiler plugin with Gradle
plugins {
id("com.cmgapps.logtag") version "2.0.0-alpha.1"
}Now you can use the @LogTag annotation in your source files
@com.cmgapps.LogTag
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Log.d(LOG_TAG, "onCreate")
}
}The compiler will generate a private property LOG_TAG with the class' name that you can use as the tag for your
log messages.
using KSP
The library supports KSP (Kotlin Symbol Processing API)
Add the processor and annotation libraries to the projects dependencies
dependencies {
implementation("com.cmgapps.logtag:log-tag:2.0.0-alpha.1")
ksp("com.cmgapps.logtag:processor:2.0.0-alpha.1")
}also get sure to apply the KSP Gradle Plugin
plugins {
id("com.google.devtools.ksp") version "<ksp-version>"
}using KAPT
Add the processor and annotation libraries to the projects dependencies
dependencies {
implementation("com.cmgapps.logtag:log-tag:2.0.0-alpha.1")
kapt("com.cmgapps.logtag:processor:2.0.0-alpha.1")
}also get sure to apply the Annotation Processor Plugin
plugins {
kotlin("kapt")
}In your source file add the com.cmgapps.LogTag annotation to the class file you want to have a log tag generated:
@com.cmgapps.LogTag
class SuperImportantClass-
For Kotlin classes this will generate an extension property to you class called
LOG_TAGyou can then use as the tag for your android log messages. -
For Java it will generate a class called
<Classname>LogTagwhich has a constant field calledLOG_TAGyou can then import to tag your android log messages -
For Jetpack Compose you can annotate the
@Composablefunction for the processor to generate a class calledComposable<Composable function name>with a companion object propertyLOG_TAG
Copyright (c) 2021-2026. Christian Grach <christian.grach@cmgapps.com>
SPDX-License-Identifier: Apache-2.0