11package dev.hotwire.core.logging
22
3- import android.util.Log
43import dev.hotwire.core.config.Hotwire
4+ import okhttp3.logging.HttpLoggingInterceptor
55
6- internal object CoreLog {
7- private const val DEFAULT_TAG = " Hotwire-Core"
8-
9- private val debugEnabled get() = Hotwire .config.debugLoggingEnabled
10-
11- internal fun d (msg : String ) = log(Log .DEBUG , msg)
12-
13- internal fun w (msg : String ) = log(Log .WARN , msg)
14-
15- internal fun e (msg : String ) = log(Log .ERROR , msg)
6+ private const val DEFAULT_TAG = " Hotwire-Core"
7+ private const val PAD_END_LENGTH = 35
168
17- private fun log (logLevel : Int , msg : String ) {
18- when (logLevel) {
19- Log .DEBUG -> if (debugEnabled) Log .d(DEFAULT_TAG , msg)
20- Log .WARN -> Log .w(DEFAULT_TAG , msg)
21- Log .ERROR -> Log .e(DEFAULT_TAG , msg)
22- }
9+ internal class HotwireHttpLogger : HttpLoggingInterceptor .Logger {
10+ override fun log (message : String ) {
11+ Hotwire .config.logger.d(DEFAULT_TAG ) { message }
2312 }
2413}
2514
26- private const val PAD_END_LENGTH = 35
15+ internal fun logVerbose (event : String , details : String = "") {
16+ Hotwire .config.logger.v(DEFAULT_TAG ) {
17+ " ${" $event " .padEnd(PAD_END_LENGTH , ' .' )} [$details ]"
18+ }
19+ }
2720
28- internal fun logEvent (event : String , details : String = "") {
29- CoreLog .d(" $event " .padEnd(PAD_END_LENGTH , ' .' ) + " [$details ]" )
21+ internal fun logDebug (event : String , details : String = "") {
22+ Hotwire .config.logger.d(DEFAULT_TAG ) {
23+ " ${" $event " .padEnd(PAD_END_LENGTH , ' .' )} [$details ]"
24+ }
3025}
3126
32- internal fun logEvent (event : String , attributes : List <Pair <String , Any >>) {
33- val description = attributes.joinToString(prefix = " [" , postfix = " ]" , separator = " , " ) {
34- " ${it.first} : ${it.second} "
27+ internal fun logDebug (event : String , attributes : List <Pair <String , Any >>) {
28+ Hotwire .config.logger.d(DEFAULT_TAG ) {
29+ val description = attributes.joinToString(prefix = " [" , postfix = " ]" , separator = " , " ) {
30+ " ${it.first} : ${it.second} "
31+ }
32+
33+ " ${" $event " .padEnd(PAD_END_LENGTH , ' .' )} $description "
3534 }
36- CoreLog .d(" $event " .padEnd(PAD_END_LENGTH , ' .' ) + " $description " )
3735}
3836
3937internal fun logWarning (event : String , details : String ) {
40- CoreLog .w(" $event " .padEnd(PAD_END_LENGTH , ' .' ) + " [$details ]" )
38+ Hotwire .config.logger.w(DEFAULT_TAG ) {
39+ " ${" $event " .padEnd(PAD_END_LENGTH , ' .' )} [$details ]"
40+ }
4141}
4242
43- internal fun logError (event : String , error : Exception ) {
44- CoreLog .e(" $event : ${error.stackTraceToString()} " )
45- }
43+ internal fun logError (event : String , throwable : Throwable ) {
44+ Hotwire .config.logger.e(DEFAULT_TAG , throwable) {
45+ " $event : ${throwable.stackTraceToString()} "
46+ }
47+ }
0 commit comments