Skip to content

Commit

Permalink
Merge pull request #24 from hotwired/strada-logging
Browse files Browse the repository at this point in the history
Move the `debugLoggingEnabled` flag to the Strada.config namespace
  • Loading branch information
jayohms authored Aug 15, 2023
2 parents 2fc64e8 + 6465dd2 commit b87bdb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 12 additions & 0 deletions strada/src/main/kotlin/dev/hotwire/strada/StradaConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package dev.hotwire.strada

class StradaConfig internal constructor() {
/**
* Set a custom JSON converter to easily decode Message.dataJson to a data
* object in received messages and to encode a data object back to json to
* reply with a custom message back to the web.
*/
var jsonConverter: StradaJsonConverter? = null

/**
* Enable debug logging to see message communication from/to the WebView.
*
* NOTE: You should not enable debug logging in production builds.
*/
var debugLoggingEnabled = false
}
9 changes: 2 additions & 7 deletions strada/src/main/kotlin/dev/hotwire/strada/StradaLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,16 @@ package dev.hotwire.strada
import android.util.Log

@Suppress("unused")
object StradaLog {
internal object StradaLog {
private const val DEFAULT_TAG = "StradaLog"

/**
* Enable debug logging to see message communication from/to the WebView.
*/
var debugLoggingEnabled = false

internal fun d(msg: String) = log(Log.DEBUG, DEFAULT_TAG, msg)

internal fun e(msg: String) = log(Log.ERROR, DEFAULT_TAG, msg)

private fun log(logLevel: Int, tag: String, msg: String) {
when (logLevel) {
Log.DEBUG -> if (debugLoggingEnabled) Log.d(tag, msg)
Log.DEBUG -> if (Strada.config.debugLoggingEnabled) Log.d(tag, msg)
Log.ERROR -> Log.e(tag, msg)
}
}
Expand Down

0 comments on commit b87bdb3

Please sign in to comment.