File tree Expand file tree Collapse file tree 9 files changed +50
-61
lines changed
src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform Expand file tree Collapse file tree 9 files changed +50
-61
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ kotlin {
9898 api(libs.koin.core)
9999 implementation(libs.koin.compose)
100100 implementation(libs.koin.compose.viewmodel)
101+ implementation(libs.kermit)
101102 }
102103 desktopMain.dependencies {
103104 implementation(compose.desktop.currentOs)
Original file line number Diff line number Diff line change 1+ package com.developersbreach.kotlindictionarymultiplatform
2+
3+ import co.touchlab.kermit.Logger
4+
5+ object Log {
6+ fun d (
7+ tag : String ,
8+ message : String ,
9+ ) {
10+ Logger .d(message, tag = tag)
11+ }
12+
13+ fun i (
14+ tag : String ,
15+ message : String ,
16+ ) {
17+ Logger .i(message, tag = tag)
18+ }
19+
20+ fun w (
21+ tag : String ,
22+ message : String ,
23+ ) {
24+ Logger .w(message, tag = tag)
25+ }
26+
27+ fun e (
28+ tag : String ,
29+ message : String ,
30+ throwable : Throwable ? = null,
31+ ) {
32+ Logger .e(message, throwable, tag = tag)
33+ }
34+ }
Original file line number Diff line number Diff line change 11package com.developersbreach.kotlindictionarymultiplatform.core
22
3+ import com.developersbreach.kotlindictionarymultiplatform.Log
34import com.developersbreach.kotlindictionarymultiplatform.data.detail.ChatCompletionRequest
45import com.developersbreach.kotlindictionarymultiplatform.data.detail.ChatCompletionResponse
56import com.developersbreach.kotlindictionarymultiplatform.data.detail.ChatMessage
@@ -115,11 +116,11 @@ object KtorHttpClient {
115116 }
116117
117118 val text = response.bodyAsText()
118- println ( " RAW RESPONSE:\n $text " )
119+ Log .i( " RawResponse " , " RAW RESPONSE:\n $text " )
119120
120121 // Parse response
121122 val chatResp = json.decodeFromString(ChatCompletionResponse .serializer(), text)
122- println ( chatResp)
123+ Log .i( " ChatResponse " , " $ chatResp" )
123124 val funcCall = chatResp.choices?.first()?.message?.functionCall ? : error(" No function call in response" )
124125
125126 // The arguments field is a JSON string: parse and decode into our DTO
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -20,10 +20,8 @@ import androidx.compose.foundation.lazy.items
2020@Composable
2121fun DetailScreen (viewModel : DetailViewModel ) {
2222 val topicState by viewModel.state.collectAsState()
23- println (" check topicState: $topicState " )
2423
2524 topicState?.let { topic ->
26- println (" Topic data fetched: $topic " )
2725 LazyColumn (modifier = Modifier .padding(16 .dp)) {
2826 item {
2927 Text (text = topic.topicName, style = MaterialTheme .typography.h5)
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import androidx.lifecycle.SavedStateHandle
44import androidx.lifecycle.ViewModel
55import androidx.lifecycle.viewModelScope
66import androidx.navigation.toRoute
7+ import com.developersbreach.kotlindictionarymultiplatform.Log
78import com.developersbreach.kotlindictionarymultiplatform.data.detail.KotlinTopicDetails
89import com.developersbreach.kotlindictionarymultiplatform.core.KtorHttpClient
910import kotlinx.coroutines.flow.MutableStateFlow
@@ -29,11 +30,11 @@ class DetailViewModel(
2930 viewModelScope.launch {
3031 try {
3132 val topic = KtorHttpClient .generateTopicDetails(topicId, API_KEY )
32- println ( " Fetched details: $topic " )
33+ Log .i( " DetailViewModel " , " Fetched details: $topic " )
3334 _state .value = topic
34- println ( " State updated with topic: $topic " )
35+ Log .i( " DetailViewModel " , " State updated with topic: $topic " )
3536 } catch (e: Exception ) {
36- println ( " Error fetching topic: ${e.message} " )
37+ Log .e( " DetailViewModel " , " Error fetching topic: ${e.message} " , e )
3738 }
3839 }
3940 }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import androidx.compose.runtime.collectAsState
1414import androidx.compose.runtime.getValue
1515import androidx.compose.ui.Modifier
1616import androidx.compose.ui.unit.dp
17+ import com.developersbreach.kotlindictionarymultiplatform.Log
1718import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
1819
1920@Composable
@@ -30,7 +31,7 @@ fun TopicScreen(
3031 ) {
3132 items(topics) { topic ->
3233 TopicItem (topic = topic, onClick = {
33- println ( " Topic clicked: ${topic.name} " )
34+ Log .i( " TopicScreen " , " Topic clicked: ${topic.name} " )
3435 onTopicClick(topic.name)
3536 })
3637 }
@@ -42,7 +43,7 @@ fun TopicItem(
4243 topic : Topic ,
4344 onClick : () -> Unit ,
4445) {
45- println ( " Rendering topic item: ${topic.name} " )
46+ Log .i( " TopicItem " , " Rendering topic item: ${topic.name} " )
4647
4748 Card (
4849 elevation = 4 .dp,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic
22
33import androidx.lifecycle.ViewModel
44import androidx.lifecycle.viewModelScope
5+ import com.developersbreach.kotlindictionarymultiplatform.Log
56import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
67import com.developersbreach.kotlindictionarymultiplatform.data.topic.repository.TopicRepository
78import kotlinx.coroutines.flow.MutableStateFlow
@@ -21,11 +22,10 @@ class TopicViewModel : ViewModel() {
2122 viewModelScope.launch {
2223 try {
2324 val topics = TopicRepository .getTopics()
24- println ( " Successfully fetched topics: $topics " )
25+ Log .i( " TopicFetch " , " Successfully fetched topics: $topics " )
2526 _topics .value = topics
2627 } catch (e: Exception ) {
27- println (" Error fetching topics: ${e.message} " )
28- e.printStackTrace()
28+ Log .e(" TopicFetch" , " Error fetching topics: ${e.message} " , e)
2929 }
3030 }
3131 }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ androidx-material = "1.12.0"
1313androidx-test-junit = " 1.2.1"
1414compose-multiplatform = " 1.7.3"
1515junit = " 4.13.2"
16+ kermit = " 2.0.4"
1617kotlin = " 2.1.10"
1718kotlinx-coroutines = " 1.10.1"
1819kotlinx-serialization-json = " 1.7.3"
@@ -23,6 +24,7 @@ ktlint = "12.2.0"
2324
2425[libraries ]
2526androidx-navigation-compose = { module = " androidx.navigation:navigation-compose" , version.ref = " navigation-compose" }
27+ kermit = { module = " co.touchlab:kermit" , version.ref = " kermit" }
2628kotlin-test = { module = " org.jetbrains.kotlin:kotlin-test" , version.ref = " kotlin" }
2729kotlin-test-junit = { module = " org.jetbrains.kotlin:kotlin-test-junit" , version.ref = " kotlin" }
2830junit = { group = " junit" , name = " junit" , version.ref = " junit" }
You can’t perform that action at this time.
0 commit comments