-
Notifications
You must be signed in to change notification settings - Fork 1
Adding SDKLogger Override in Example App #32
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 72 additions & 5 deletions
77
app/src/main/java/com/amazon/connect/chat/androidchatexample/utils/CustomLogger.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,97 @@ | ||
package com.amazon.connect.chat.androidchatexample.utils | ||
|
||
import com.amazon.connect.chat.sdk.utils.logger.ChatSDKLogger | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
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 | ||
import java.util.TimeZone | ||
import kotlin.io.path.Path | ||
import kotlin.io.path.appendText | ||
import kotlin.io.path.createFile | ||
import kotlin.io.path.exists | ||
|
||
class CustomLogger : ChatSDKLogger { | ||
private var outputFileDir: File? = null | ||
private val job = SupervisorJob() | ||
private val coroutineScope = CoroutineScope(job + Dispatchers.IO) | ||
|
||
private val currentTimeMillis = System.currentTimeMillis() | ||
private val loggerCreationDateAndTime = CommonUtils.formatDate(currentTimeMillis, false) | ||
|
||
override fun logVerbose(message: () -> String) { | ||
// Custom logging logic | ||
println("VERBOSE: ${message()}") | ||
val logMessage = "VERBOSE: ${message()}" | ||
println(logMessage) | ||
coroutineScope.launch { | ||
writeToAppTempFile(logMessage) | ||
} | ||
} | ||
|
||
override fun logInfo(message: () -> String) { | ||
// Custom logging logic | ||
println("INFO: ${message()}") | ||
val logMessage = "INFO: ${message()}" | ||
println(logMessage) | ||
coroutineScope.launch { | ||
writeToAppTempFile(logMessage) | ||
} | ||
} | ||
|
||
override fun logDebug(message: () -> String) { | ||
// Custom logging logic | ||
println("DEBUG: ${message()}") | ||
val logMessage = "DEBUG: ${message()}" | ||
println(logMessage) | ||
coroutineScope.launch { | ||
writeToAppTempFile(logMessage) | ||
} | ||
|
||
} | ||
|
||
override fun logWarn(message: () -> String) { | ||
// Custom logging logic | ||
println("WARN: ${message()}") | ||
val logMessage = "WARN: ${message()}" | ||
println(logMessage) | ||
coroutineScope.launch { | ||
writeToAppTempFile(logMessage) | ||
} | ||
} | ||
|
||
override fun logError(message: () -> String) { | ||
// Custom logging logic | ||
println("ERROR: ${message()}") | ||
val logMessage = "ERROR: ${message()}" | ||
println(logMessage) | ||
coroutineScope.launch { | ||
writeToAppTempFile(logMessage) | ||
} | ||
} | ||
|
||
fun setLogOutputDir(tempFile: File) { | ||
outputFileDir = tempFile | ||
} | ||
|
||
private suspend fun writeToAppTempFile(content: String): Result<Boolean> { | ||
return withContext(Dispatchers.IO) { | ||
runCatching { | ||
val currentTimeMillis = System.currentTimeMillis() | ||
val formattedDateTimeForLogs = CommonUtils.formatDate(currentTimeMillis, true) | ||
if (outputFileDir == null || !outputFileDir!!.exists() || !outputFileDir!!.isDirectory()) { | ||
return@runCatching false | ||
} | ||
val filePath = Path(outputFileDir!!.absolutePath, "$loggerCreationDateAndTime-amazon-connect-logs.txt") | ||
|
||
if (!filePath.exists()) { | ||
filePath.createFile() | ||
} | ||
|
||
filePath.appendText("[$formattedDateTimeForLogs] $content \n") | ||
true | ||
} | ||
} | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
chat-sdk/src/main/java/com/amazon/connect/chat/sdk/ChatSession.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.