Kotlin compiler plugin to emit method execution metadata in logging
Go to file
Harsh Shandilya 174f672291
chore(README): document `loggerFunction` parameter
2023-09-10 14:22:30 +05:30
.github chore(deps): update actions/cache action to v3.3.2 2023-09-09 05:57:05 +00:00
.idea refactor(build): realign to Kotlin 1.9.0 2023-08-30 19:22:44 +05:30
artifact-info-template feat: refactor build and flesh out Gradle plugin 2023-08-30 19:25:03 +05:30
build-logic fix(build): restore snapshot publishing 2023-08-31 21:18:08 +05:30
compiler-plugin fix(compiler-plugin): add workaround for nested logger resolution 2023-09-10 14:14:23 +05:30
gradle chore(deps): update plugin dokka to v1.9.0 2023-08-31 19:53:27 +00:00
gradle-plugin fix(gradle-plugin): source `runtime` dependency from `ArtifactInfo` 2023-09-01 01:01:51 +05:30
runtime fix(release): add missing POM metadata 2023-08-31 23:16:20 +05:30
sample-jvm refactor(sample-jvm): apply compiler plugin manually 2023-09-03 19:31:23 +05:30
sample-kmp refactor(sample-kmp): apply compiler plugin manually 2023-09-03 19:59:52 +05:30
.editorconfig Initial commit 2023-08-18 04:13:01 +05:30
.git-blame-ignore-revs chore: set up blame ignore-revs file 2023-08-19 02:04:29 +05:30
.gitignore feat: refactor build and flesh out Gradle plugin 2023-08-30 19:25:03 +05:30
LICENSE chore(build): add basic publishing info 2023-08-29 10:55:10 +05:30
README.md chore(README): document `loggerFunction` parameter 2023-09-10 14:22:30 +05:30
build.gradle.kts feat: refactor build and flesh out Gradle plugin 2023-08-30 19:25:03 +05:30
gradle.properties chore(release): start next development iteration 2023-09-01 01:02:39 +05:30
gradlew Initial commit 2023-08-18 04:13:01 +05:30
gradlew.bat Initial commit 2023-08-18 04:13:01 +05:30
settings.gradle.kts feat: refactor build and flesh out Gradle plugin 2023-08-30 19:25:03 +05:30

README.md

TraceLog Maven Central

Kotlin compiler plugin to automate println debugging, because debuggers are for people smarter than me.

Installation

Apply the Gradle plugin to your Kotlin project

plugins {
  id("dev.msfjarvis.tracelog") version "0.1.3"
}

Optionally configure the annotation class and logger method (defaults shown below)

traceLog {
  loggerFunction.set("kotlin.io.println")
  annotationClass.set("dev/msfjarvis/tracelog/runtime/annotations/DebugLog")
}

The loggerFunction parameter must be a fully qualified to a static method with a single parameter of the type Any?.

fun recordMessage() {} // Bad, no parameter
fun recordMessage(p0: String, p1: Int) {} // Bad, multiple parameters and incorrect types
fun recordMessage(p0: Any?) {} // Good, single parameter with correct type

[!NOTE] Due to a limitation in how TraceLog resolves the logger function, you might need to add @JvmStatic on the method for TraceLog to be able to find it. This will be fixed in a future release.

Usage

Currently, this prints out a basic textual representation of the method's inputs and execution time. That is, given this code:

@DebugLog
fun debuggableFunction(p0: String): String {
  return "Debugging is cool!"
}

fun main() {
  debuggableFunction("First parameter")
}

The compiler plugin will generate code that writes the following messages

⇢ debuggableFunction(p0=First parameter)
⇠ debuggableFunction [214.209us] = Debugging is cool!

Compatibility

Kotlin Version TraceLog Version
1.9.0 0.1.x