Merge pull request #1204 from vector-im/feature/increase_file_log_size

Increase file logger size
This commit is contained in:
Valere 2020-04-03 16:40:18 +02:00 committed by GitHub
commit 42d61944b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View file

@ -26,7 +26,7 @@ Build 🧱:
-
Other changes:
-
- Increase File Logger capacities ( + use dev log preferences)
Changes in RiotX 0.18.1 (2020-03-17)
===================================================

View file

@ -35,13 +35,25 @@ import java.util.logging.Logger
import javax.inject.Inject
import javax.inject.Singleton
private const val LOG_SIZE_BYTES = 20 * 1024 * 1024 // 20MB
private const val LOG_ROTATION_COUNT = 3
private const val SIZE_20MB = 20 * 1024 * 1024
private const val SIZE_50MB = 50 * 1024 * 1024
@Singleton
class VectorFileLogger @Inject constructor(val context: Context, private val vectorPreferences: VectorPreferences) : Timber.DebugTree() {
private val maxLogSizeByte: Int
private val logRotationCount: Int
init {
if (vectorPreferences.labAllowedExtendedLogging()) {
maxLogSizeByte = SIZE_50MB
logRotationCount = 15
} else {
maxLogSizeByte = SIZE_20MB
logRotationCount = 7
}
}
private val sLogger = Logger.getLogger("im.vector.riotx")
private var sFileHandler: FileHandler? = null
private var sCacheDirectory: File? = null
@ -61,7 +73,7 @@ class VectorFileLogger @Inject constructor(val context: Context, private val vec
setLogDirectory(File(logsDirectoryFile))
try {
if (sCacheDirectory != null) {
sFileHandler = FileHandler(sCacheDirectory!!.absolutePath + "/" + sFileName + ".%g.txt", LOG_SIZE_BYTES, LOG_ROTATION_COUNT)
sFileHandler = FileHandler(sCacheDirectory!!.absolutePath + "/" + sFileName + ".%g.txt", maxLogSizeByte, logRotationCount)
sFileHandler?.formatter = LogFormatter()
sLogger.useParentHandlers = false
sLogger.level = Level.ALL
@ -117,7 +129,7 @@ class VectorFileLogger @Inject constructor(val context: Context, private val vec
sFileHandler!!.flush()
val absPath = sCacheDirectory?.absolutePath ?: return emptyList()
for (i in 0..LOG_ROTATION_COUNT) {
for (i in 0..logRotationCount) {
val filepath = "$absPath/$sFileName.$i.txt"
val file = File(filepath)
if (file.exists()) {