Skip to content

Commit

Permalink
Fixed exception in 'DataLogger' class.
Browse files Browse the repository at this point in the history
Signed-off-by: Umair Adil <[email protected]>
  • Loading branch information
Umair Adil committed Nov 27, 2018
1 parent 471732a commit 6537b06
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
4 changes: 2 additions & 2 deletions plog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 12
versionName "v0.12"
versionCode 16
versionName "0.16"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
61 changes: 33 additions & 28 deletions plog/src/main/java/com/blackbox/plog/dataLogs/DataLogger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,43 +71,48 @@ class DataLogger(var logFileName: String = "log") {
}
}

private fun writeDataLog(dataToWrite: String, overwrite: Boolean = false) {
private fun writeDataLog(dataToWrite: String?, overwrite: Boolean = false) {

val logFilePath = setupFilePaths(logFileName, isPLog = false)
dataLoggerCalledBeforePLoggerException()
dataToWrite?.let {

val shouldLog: Pair<Boolean, String>
val f = checkFileExists(logFilePath, isPLog = false)
val logFilePath = setupFilePaths(logFileName, isPLog = false)
dataLoggerCalledBeforePLoggerException()

if (!PART_FILE_CREATED_DATALOG) {
shouldLog = LogWriter.shouldWriteLog(f, isPLog = false, logFileName = logFileName)
} else {
shouldLog = LogWriter.shouldWriteLog(File(CURRENT_PART_FILE_PATH_DATALOG), isPLog = false, logFileName = logFileName)
}

if (PLogImpl.getLogsConfig(PLog)?.encryptionEnabled!!) {
val shouldLog: Pair<Boolean, String>
val f = checkFileExists(logFilePath, isPLog = false)

if (shouldLog.first) {
if (overwrite)
writeToFileEncrypted(dataToWrite, PLogImpl.getLogsConfig(PLog)?.secretKey!!, shouldLog.second)
else
appendToFileEncrypted(dataToWrite, PLogImpl.getLogsConfig(PLog)?.secretKey!!, shouldLog.second)
if (!PART_FILE_CREATED_DATALOG) {
shouldLog = LogWriter.shouldWriteLog(f, isPLog = false, logFileName = logFileName)
} else {
shouldLog = LogWriter.shouldWriteLog(File(CURRENT_PART_FILE_PATH_DATALOG), isPLog = false, logFileName = logFileName)
}

} else {
if (PLogImpl.getLogsConfig(PLog)?.encryptionEnabled!!) {

val secretKey = PLogImpl.getLogsConfig(PLog)?.secretKey!!

if (shouldLog.first) {
if (overwrite)
writeToFile(shouldLog.second, dataToWrite)
else
appendToFile(shouldLog.second, dataToWrite)
if (shouldLog.first) {
if (overwrite)
writeToFileEncrypted(it, secretKey, shouldLog.second)
else
appendToFileEncrypted(it, secretKey, shouldLog.second)
}

} else {

if (shouldLog.first) {
if (overwrite)
writeToFile(shouldLog.second, it)
else
appendToFile(shouldLog.second, it)
}
}
}

if (PLogImpl.getLogsConfig(PLog)?.isDebuggable!!)
Log.i(PLog.TAG, dataToWrite)
if (PLogImpl.getLogsConfig(PLog)?.isDebuggable!!)
Log.i(PLog.TAG, it)

//Check if auto Export is enabled, and then export it
autoExportLogType(dataToWrite, logFileName)
//Check if auto Export is enabled, and then export it
autoExportLogType(it, logFileName)
}
}
}

0 comments on commit 6537b06

Please sign in to comment.