Skip to content

Instantly share code, notes, and snippets.

@caseykulm
Last active September 9, 2019 18:11
Show Gist options
  • Save caseykulm/f54572713d21c614cc1261ea955697ca to your computer and use it in GitHub Desktop.
Save caseykulm/f54572713d21c614cc1261ea955697ca to your computer and use it in GitHub Desktop.
import timber.log.Timber
object Klocky {
private val tagToLastTimeMap = mutableMapOf<String, Long>()
@JvmOverloads
fun stamp(tag: String, message: String = "", restart: Boolean = false) {
val currTime = System.currentTimeMillis()
if (restart) tagToLastTimeMap.remove(tag)
val log = StringBuilder("tag: $tag")
.apply { tagToLastTimeMap[tag]?.let { append(", diff: ${(currTime - it)} millis") } }
.apply { if (message.isNotEmpty()) append(", message: $message") }
.apply { append(", time: $currTime UTC millis") }
Timber.d(log.toString())
tagToLastTimeMap[tag] = currTime
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment