Skip to content

Repository files navigation

Log TAG Generator Build & Test codecov

License MavenCentral

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

Using Kotlin Compiler Plugin

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:

  1. Enable K2 Mode for the Kotlin IntelliJ plugin.
  2. Open the Registry
  3. 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 Annotation Processors

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")
}

Code

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_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

License

Copyright (c) 2021-2026. Christian Grach <christian.grach@cmgapps.com>

SPDX-License-Identifier: Apache-2.0

About

This is an annotation processor that will generate an appropriate log tag for Android Log messages.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages