-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App lifecycle logging & log persistence (#322)
* implemented force quit logger * cleanup * remove magic number * Update build.gradle * Update build.gradle * Store and retrieve the last force quit timestamp in shared preferences before checking for force quits in Radar.kt * first draft * passing unit test and manual tests * cleanup * add in-code documentation * allow custom edting of timestamp * changed android into individual files * format * added feature flag * fix test * bump version * add dynamic updated feature flag * fixed flag setter * bump beta version * make logging backgrounding and resign active safe if not init * fixed tests * test-cleanup * bump-beta * cleanup * restart ci * addressed code review * cleanup * remove redundent check * bump version * remove un-needed dependency * cleanup * cleanup file storage * minor bug fix for buffer * bug fix, old implementation needs to also pass in custom createdAt * fix race condition * review changes * change naming and formatting * add check to json string * add calls to app callback * remove dead line * rename methods * increase presist freq * add locks * add lock * fix lock * bump version back to beta
- Loading branch information
1 parent
a1c76fd
commit dd0cdc0
Showing
13 changed files
with
464 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.radar.sdk.util | ||
import android.content.Context | ||
import java.io.File | ||
import java.io.FileInputStream | ||
import java.io.FileNotFoundException | ||
import java.io.FileOutputStream | ||
|
||
class RadarFileStorage(private val context: Context) { | ||
fun writeData(subDir: String = "", filename: String, content: String) { | ||
var fileOutputStream: FileOutputStream | ||
try { | ||
val directory = if (subDir.isNotEmpty()) File(context.filesDir, subDir) else context.filesDir | ||
directory.mkdirs() | ||
val file = File(directory, filename) | ||
fileOutputStream = FileOutputStream(file) | ||
fileOutputStream.use { it.write(content.toByteArray()) } | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
fun readFileAtPath(subDir: String = "", filePath: String): String { | ||
var fileInputStream: FileInputStream? = null | ||
try { | ||
val directory = if (subDir.isNotEmpty()) File(context.filesDir, subDir) else context.filesDir | ||
val file = File(directory, filePath) | ||
fileInputStream = FileInputStream(file) | ||
val inputStreamReader = fileInputStream?.reader() | ||
return inputStreamReader?.readText() ?: "" | ||
} catch (e: FileNotFoundException) { | ||
return "" | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} finally { | ||
fileInputStream?.close() | ||
} | ||
return "" | ||
} | ||
|
||
fun deleteFileAtPath(subDir: String = "", filePath: String): Boolean { | ||
try { | ||
val directory = if (subDir.isNotEmpty()) File(context.filesDir, subDir) else context.filesDir | ||
val file = File(directory, filePath) | ||
return file.delete() | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
return false | ||
} | ||
|
||
fun sortedFilesInDirectory(directoryPath: String, comparator: Comparator<File>): Array<File>? { | ||
try { | ||
val directory = File(context.filesDir, directoryPath) | ||
var files = directory.listFiles() | ||
files?.sortWith(comparator) | ||
return files | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
return null | ||
} | ||
} |
This file contains 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,23 +1,39 @@ | ||
package io.radar.sdk.util | ||
|
||
import android.content.Context | ||
import io.radar.sdk.Radar | ||
import io.radar.sdk.model.RadarLog | ||
import java.util.Date | ||
|
||
internal interface RadarLogBuffer { | ||
|
||
abstract val context: Context | ||
|
||
/** | ||
* Write a log to the buffer | ||
* | ||
* @param[level] log level | ||
* @param[message] log message | ||
*/ | ||
fun write(level: Radar.RadarLogLevel, message: String, type: Radar.RadarLogType?) | ||
fun write( | ||
level: Radar.RadarLogLevel, | ||
type: Radar.RadarLogType?, | ||
message: String, | ||
createdAt: Date = Date() | ||
) | ||
|
||
/** | ||
* Creates a stash of the logs currently in the buffer and returns them as a [Flushable] so that a successful | ||
* callback can cleanup this log buffer by deleting old log files. | ||
* | ||
* @return a [Flushable] containing all stored logs | ||
*/ | ||
fun getFlushableLogsStash(): Flushable<RadarLog> | ||
fun getFlushableLogs(): Flushable<RadarLog> | ||
|
||
/** | ||
* Persist the logs to disk | ||
*/ | ||
fun persistLogs() | ||
|
||
fun setPersistentLogFeatureFlag(persistentLogFeatureFlag: Boolean) | ||
} |
Oops, something went wrong.