Skip to content

Commit

Permalink
Migrated logging module from Java to Kotlin (#5972)
Browse files Browse the repository at this point in the history
* Migrated logging module from Java to Kotlin

* Rename .java to .kt

---------

Co-authored-by: Nicolas Raoul <[email protected]>
  • Loading branch information
Saifuddin53 and nicolas-raoul authored Nov 29, 2024
1 parent 1afff73 commit d6c4cab
Show file tree
Hide file tree
Showing 11 changed files with 500 additions and 508 deletions.
105 changes: 0 additions & 105 deletions app/src/main/java/fr/free/nrw/commons/logging/CommonsLogSender.java

This file was deleted.

107 changes: 107 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/logging/CommonsLogSender.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package fr.free.nrw.commons.logging

import android.content.Context

import android.os.Bundle
import javax.inject.Inject
import javax.inject.Singleton

import fr.free.nrw.commons.auth.SessionManager
import fr.free.nrw.commons.utils.ConfigUtils
import fr.free.nrw.commons.utils.ConfigUtils.getVersionNameWithSha
import fr.free.nrw.commons.utils.DeviceInfoUtil
import org.acra.data.CrashReportData


/**
* Class responsible for sending logs to developers
*/
@Singleton
class CommonsLogSender @Inject constructor(
private val sessionManager: SessionManager,
private val context: Context
) : LogsSender(sessionManager) {


companion object {
private const val LOGS_PRIVATE_EMAIL = "[email protected]"
private const val LOGS_PRIVATE_EMAIL_SUBJECT = "Commons Android App (%s) Logs"
private const val BETA_LOGS_PRIVATE_EMAIL_SUBJECT = "Commons Beta Android App (%s) Logs"
}

init {
val isBeta = ConfigUtils.isBetaFlavour
logFileName = if (isBeta) "CommonsBetaAppLogs.zip" else "CommonsAppLogs.zip"
val emailSubjectFormat = if (isBeta)
BETA_LOGS_PRIVATE_EMAIL_SUBJECT
else
LOGS_PRIVATE_EMAIL_SUBJECT
emailSubject = emailSubjectFormat.format(sessionManager.userName)
emailBody = getExtraInfo()
mailTo = LOGS_PRIVATE_EMAIL
}

/**
* Attach any extra meta information about the user or device that might help in debugging.
* @return String with extra meta information useful for debugging.
*/
public override fun getExtraInfo(): String {
return buildString {
// Getting API Level
append("API level: ")
.append(DeviceInfoUtil.getAPILevel())
.append("\n")

// Getting Android Version
append("Android version: ")
.append(DeviceInfoUtil.getAndroidVersion())
.append("\n")

// Getting Device Manufacturer
append("Device manufacturer: ")
.append(DeviceInfoUtil.getDeviceManufacturer())
.append("\n")

// Getting Device Model
append("Device model: ")
.append(DeviceInfoUtil.getDeviceModel())
.append("\n")

// Getting Device Name
append("Device: ")
.append(DeviceInfoUtil.getDevice())
.append("\n")

// Getting Network Type
append("Network type: ")
.append(DeviceInfoUtil.getConnectionType(context))
.append("\n")

// Getting App Version
append("App version name: ")
.append(context.getVersionNameWithSha())
.append("\n")

// Getting Username
append("User name: ")
.append(sessionManager.userName)
.append("\n")
}
}

/**
* Determines if the log sending process requires the app to be in the foreground.
* @return False as it does not require foreground execution.
*/
override fun requiresForeground(): Boolean = false

/**
* Sends logs to developers. Implementation can be extended.
*/
override fun send(
context: Context,
errorContent: CrashReportData,
extras: Bundle) {
// Add logic here if needed.
}
}
145 changes: 0 additions & 145 deletions app/src/main/java/fr/free/nrw/commons/logging/FileLoggingTree.java

This file was deleted.

Loading

0 comments on commit d6c4cab

Please sign in to comment.