Kotlin compiler plugin to emit method execution metadata in logging
Go to file
renovate[bot] 0d082f62a8
chore(deps): update dependency macos to v14
2024-04-23 05:38:05 +00:00
.github chore(deps): update dependency macos to v14 2024-04-23 05:38: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 fix(deps): update dependency com.android.tools.build:gradle to v8.3.2 2024-04-13 09:00:03 +00:00
gradle-plugin chore(deps): update plugin org.gradle.toolchains.foojay-resolver-convention to v0.8.0 2024-01-14 02:57:00 +00:00
runtime fix(release): add missing POM metadata 2023-08-31 23:16:20 +05:30
sample-jvm fix(sample-jvm): setup shadow plugin 2023-09-14 23:28:37 +05:30
sample-kmp chore: suppress unused parameter warnings 2023-09-14 23:28:37 +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 chore(deps): update plugin org.gradle.toolchains.foojay-resolver-convention to v0.8.0 2024-01-14 02:57:00 +00:00

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