Merge pull request #1204 from vector-im/feature/increase_file_log_size
Increase file logger size
This commit is contained in:
commit
42d61944b5
|
@ -26,7 +26,7 @@ Build 🧱:
|
|||
-
|
||||
|
||||
Other changes:
|
||||
-
|
||||
- Increase File Logger capacities ( + use dev log preferences)
|
||||
|
||||
Changes in RiotX 0.18.1 (2020-03-17)
|
||||
===================================================
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Reference in New Issue