diff --git a/gradle.properties b/gradle.properties index 47e7482..de3e966 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,4 @@ POM_LICENCE_DIST=repo POM_DEVELOPER_ID=bolteu POM_DEVELOPER_NAME=Bolt Technologies OÜ -VERSION_NAME=1.0.1 +VERSION_NAME=1.0.2 diff --git a/kalev-android/gradle.properties b/kalev-android/gradle.properties index 22a5e95..e3d580e 100644 --- a/kalev-android/gradle.properties +++ b/kalev-android/gradle.properties @@ -1,5 +1,4 @@ POM_ARTIFACT_ID=kalev-android POM_NAME=kalev-android POM_PACKAGING=aar -POM_DESCRIPTION=New age logging for Android -VERSION_NAME=1.0.1 \ No newline at end of file +POM_DESCRIPTION=New age logging for Android \ No newline at end of file diff --git a/kalev-lib/gradle.properties b/kalev-lib/gradle.properties index 7d676a2..20cb838 100644 --- a/kalev-lib/gradle.properties +++ b/kalev-lib/gradle.properties @@ -1,5 +1,4 @@ POM_ARTIFACT_ID=kalev POM_NAME=kalev POM_PACKAGING=jar -POM_DESCRIPTION=New age logging for JVM -VERSION_NAME=1.0.1 \ No newline at end of file +POM_DESCRIPTION=New age logging for JVM \ No newline at end of file diff --git a/kalev-lib/src/main/java/eu/bolt/kalev/Kalev.kt b/kalev-lib/src/main/java/eu/bolt/kalev/Kalev.kt index f12a830..8aa6206 100644 --- a/kalev-lib/src/main/java/eu/bolt/kalev/Kalev.kt +++ b/kalev-lib/src/main/java/eu/bolt/kalev/Kalev.kt @@ -1,5 +1,6 @@ package eu.bolt.kalev +@Suppress("MemberVisibilityCanBePrivate", "unused") object Kalev { const val V = "v" @@ -8,11 +9,18 @@ object Kalev { const val W = "w" const val E = "e" + /** + * No Operation mode. + * In case of enabled NOP mode Kalev will not create log entries and dispatch them to consumers + */ + var nop = false + private val nopEntry = NopLogEntry + private val consumers = mutableListOf() @JvmStatic fun d(message: String) { - LogEntry().log(message, D) + getEntry().log(message, D) } @JvmStatic @@ -22,7 +30,7 @@ object Kalev { @JvmStatic fun e(message: String) { - LogEntry().log(message, E) + getEntry().log(message, E) } @JvmStatic @@ -32,7 +40,7 @@ object Kalev { @JvmStatic fun i(message: String) { - LogEntry().log(message, I) + getEntry().log(message, I) } @JvmStatic @@ -42,7 +50,7 @@ object Kalev { @JvmStatic fun v(message: String) { - LogEntry().log(message, V) + getEntry().log(message, V) } @JvmStatic @@ -52,7 +60,7 @@ object Kalev { @JvmStatic fun w(message: String) { - LogEntry().log(message, W) + getEntry().log(message, W) } @JvmStatic @@ -62,17 +70,17 @@ object Kalev { @JvmStatic fun with(key: String, value: Any?): LogEntry { - return LogEntry().with(key, value) + return getEntry().with(key, value) } @JvmStatic fun tag(tag: String): LogEntry { - return LogEntry().tag(tag) + return getEntry().tag(tag) } @JvmStatic fun with(error: Throwable): LogEntry { - return LogEntry().with(error) + return getEntry().with(error) } @JvmStatic @@ -80,6 +88,14 @@ object Kalev { consumers.add(consumer) } + fun getEntry(): LogEntry { + return if (nop) { + nopEntry + } else { + LogEntry() + } + } + internal fun log(entry: LogEntry) { consumers.forEach { it.log(entry) diff --git a/kalev-lib/src/main/java/eu/bolt/kalev/LogEntry.kt b/kalev-lib/src/main/java/eu/bolt/kalev/LogEntry.kt index c97417e..c3736b7 100644 --- a/kalev-lib/src/main/java/eu/bolt/kalev/LogEntry.kt +++ b/kalev-lib/src/main/java/eu/bolt/kalev/LogEntry.kt @@ -2,7 +2,8 @@ package eu.bolt.kalev import java.util.Date -class LogEntry { +@Suppress("unused") +open class LogEntry internal constructor() { var tag: String? = null private set @@ -14,42 +15,42 @@ class LogEntry { lateinit var message: String val data = mutableMapOf() - fun with(key: String, value: Any?): LogEntry { + open fun with(key: String, value: Any?): LogEntry { data[key] = value return this } - fun with(throwable: Throwable): LogEntry { + open fun with(throwable: Throwable): LogEntry { this.throwable = throwable return this } - fun tag(tag: String): LogEntry { + open fun tag(tag: String): LogEntry { this.tag = tag return this } - fun v(message: String) { + open fun v(message: String) { log(message, Kalev.V) } - fun d(message: String) { + open fun d(message: String) { log(message, Kalev.D) } - fun i(message: String) { + open fun i(message: String) { log(message, Kalev.I) } - fun w(message: String) { + open fun w(message: String) { log(message, Kalev.W) } - fun e(message: String) { + open fun e(message: String) { log(message, Kalev.E) } - internal fun log(message: String, severity: String) { + internal open fun log(message: String, severity: String) { this.severity = severity timestamp = Date().time this.message = message diff --git a/kalev-lib/src/main/java/eu/bolt/kalev/NopLogEntry.kt b/kalev-lib/src/main/java/eu/bolt/kalev/NopLogEntry.kt new file mode 100644 index 0000000..38edb25 --- /dev/null +++ b/kalev-lib/src/main/java/eu/bolt/kalev/NopLogEntry.kt @@ -0,0 +1,20 @@ +package eu.bolt.kalev + +object NopLogEntry : LogEntry() { + + override fun with(key: String, value: Any?): LogEntry { + return this + } + + override fun with(throwable: Throwable): LogEntry { + return this + } + + override fun tag(tag: String): LogEntry { + return this + } + + override fun log(message: String, severity: String) { + // do nothing + } +}