
Generate compile-time LOG_TAG constants and extension properties for Android logging via annotation processing or compiler plugin; supports Java class constants and composable-function companion tags.
This is a Kotlin compiler plugin/annotation processor that will generate an appropriate log tag for 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.3"
}
logTag {
tagName = "CUSTOM_TAG" // Defaults to "LOG_TAG"
}Set tagName to choose the name of the generated tag property.
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.
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.3")
ksp("com.cmgapps.logtag:processor:2.0.0-alpha.3")
}also get sure to apply the KSP Gradle Plugin
plugins {
id("com.google.devtools.ksp") version "<ksp-version>"
}To generate the appropriate Log tag for your Android project, set the min SDK version for the KSP processor
ksp {
arg("logtag.androidMinSdkVersion", "<Your Android MIN SDK Version a.k.a. android.default.minSdk>")
}for android.util.Log Tags on Android API <26 can only have 23 characters and will automatically be truncated.
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 SuperImportantClassFor Kotlin classes this will generate an extension property to you class called LOG_TAG
you can then use as the tag for your android log messages.
For Java it will generate a class called <Classname>LogTag which has a constant field called LOG_TAG you can
then import to tag your android log messages
For Jetpack Compose you can annotate the @Composable function for the processor to generate a class called
Composable<Composable function name> with a companion object property LOG_TAG
Copyright (c) 2021-2026. Christian Grach <christian.grach@cmgapps.com>
SPDX-License-Identifier: Apache-2.0
This is a Kotlin compiler plugin/annotation processor that will generate an appropriate log tag for 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.3"
}
logTag {
tagName = "CUSTOM_TAG" // Defaults to "LOG_TAG"
}Set tagName to choose the name of the generated tag property.
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.
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.3")
ksp("com.cmgapps.logtag:processor:2.0.0-alpha.3")
}also get sure to apply the KSP Gradle Plugin
plugins {
id("com.google.devtools.ksp") version "<ksp-version>"
}To generate the appropriate Log tag for your Android project, set the min SDK version for the KSP processor
ksp {
arg("logtag.androidMinSdkVersion", "<Your Android MIN SDK Version a.k.a. android.default.minSdk>")
}for android.util.Log Tags on Android API <26 can only have 23 characters and will automatically be truncated.
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 SuperImportantClassFor Kotlin classes this will generate an extension property to you class called LOG_TAG
you can then use as the tag for your android log messages.
For Java it will generate a class called <Classname>LogTag which has a constant field called LOG_TAG you can
then import to tag your android log messages
For Jetpack Compose you can annotate the @Composable function for the processor to generate a class called
Composable<Composable function name> with a companion object property LOG_TAG
Copyright (c) 2021-2026. Christian Grach <christian.grach@cmgapps.com>
SPDX-License-Identifier: Apache-2.0