Skip to content

add toggle to enable/disable logging #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ interface ChatSDKLogger {
fun logDebug(message: () -> String)
fun logWarn(message: () -> String)
fun logError(message: () -> String)
fun setLoggingEnabled(enabled: Boolean)
}
```

#### `SDKLogger.setLoggingEnabled`
This API will allow you to enable and disable logging.

```
fun setLoggingEnabled(enabled: Boolean) {
this.logger.setLoggingEnabled(enabled)
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileNotFoundException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
Expand All @@ -25,8 +24,16 @@ class CustomLogger : ChatSDKLogger {
private val currentTimeMillis = System.currentTimeMillis()
private val loggerCreationDateAndTime = CommonUtils.formatDate(currentTimeMillis, false)

private var loggingEnabled: Boolean = true

//Custom logging logic
override fun setLoggingEnabled(enabled: Boolean) {
this.loggingEnabled = enabled
}

override fun logVerbose(message: () -> String) {
// Custom logging logic
if (!loggingEnabled) return
val logMessage = "VERBOSE: ${message()}"
println(logMessage)
coroutineScope.launch {
Expand All @@ -36,6 +43,7 @@ class CustomLogger : ChatSDKLogger {

override fun logInfo(message: () -> String) {
// Custom logging logic
if (!loggingEnabled) return
val logMessage = "INFO: ${message()}"
println(logMessage)
coroutineScope.launch {
Expand All @@ -45,16 +53,17 @@ class CustomLogger : ChatSDKLogger {

override fun logDebug(message: () -> String) {
// Custom logging logic
if (!loggingEnabled) return
val logMessage = "DEBUG: ${message()}"
println(logMessage)
coroutineScope.launch {
writeToAppTempFile(logMessage)
}

}

override fun logWarn(message: () -> String) {
// Custom logging logic
if (!loggingEnabled) return
val logMessage = "WARN: ${message()}"
println(logMessage)
coroutineScope.launch {
Expand All @@ -64,6 +73,7 @@ class CustomLogger : ChatSDKLogger {

override fun logError(message: () -> String) {
// Custom logging logic
if (!loggingEnabled) return
val logMessage = "ERROR: ${message()}"
println(logMessage)
coroutineScope.launch {
Expand Down Expand Up @@ -94,4 +104,4 @@ class CustomLogger : ChatSDKLogger {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.amazon.connect.chat.sdk.model

import com.amazon.connect.chat.sdk.utils.Constants
import com.amazon.connect.chat.sdk.utils.logger.SDKLogger
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -72,7 +73,7 @@ data class QuickReplyContent(
val subtitle = quickReply.data.content.subtitle ?: "" // Fallback to empty string if null
QuickReplyContent(title, subtitle, options)
} catch (e: Exception) {
println("Error decoding QuickReplyContent: ${e.message}")
SDKLogger.logger.logError{"MessageContent: Error decoding QuickReplyContent: ${e.message}"}
null
}
}
Expand Down Expand Up @@ -130,14 +131,13 @@ data class ListPickerContent(
val imageUrl = listPicker.data.content.imageData ?: ""
ListPickerContent(title, subtitle, imageUrl, options)
} catch (e: Exception) {
println("Error decoding ListPickerContent: ${e.message}")
SDKLogger.logger.logError{"MessageContent: Error decoding ListPickerContent: ${e.message}"}
null
}
}
}
}


// Time Picker
@Serializable
data class TimeSlot(
Expand Down Expand Up @@ -202,7 +202,7 @@ data class TimePickerContent(
timeslots = contentData.timeslots
)
} catch (e: SerializationException) {
println("Error decoding TimePickerContent: ${e.localizedMessage}")
SDKLogger.logger.logError{"MessageContent: Error decoding TimePickerContent: ${e.localizedMessage}"}
null
}
}
Expand Down Expand Up @@ -251,7 +251,7 @@ data class CarouselContent(
elements = contentData.elements
)
} catch (e: SerializationException) {
println("Error decoding CarouselContent: ${e.localizedMessage}")
SDKLogger.logger.logError{"MessageContent: Error decoding CarouselContent: ${e.localizedMessage}"}
null
}
}
Expand Down Expand Up @@ -314,9 +314,9 @@ data class PanelContent(
options = contentData.elements
)
} catch (e: SerializationException) {
println("Error decoding PanelContent: ${e.localizedMessage}")
SDKLogger.logger.logError{"MessageContent: Error decoding PanelContent: ${e.localizedMessage}"}
null
}
}
}
}
}
Loading
Loading