FUS: make max file size for log files configurable

This commit is contained in:
Svetlana.Zemlyanskaya
2019-04-02 20:42:26 +02:00
parent 049bd33e3e
commit bcbdf38f99
3 changed files with 10 additions and 6 deletions
@@ -19,7 +19,7 @@ interface StatisticsEventLogWriter {
fun cleanup()
}
class StatisticsEventLogFileWriter(private val recorderId: String) : StatisticsEventLogWriter {
class StatisticsEventLogFileWriter(private val recorderId: String, private val maxFileSize: String) : StatisticsEventLogWriter {
private var fileAppender: StatisticsEventLogFileAppender? = null
private val eventLogger: Logger = Logger.getLogger("event.logger.$recorderId")
@@ -33,7 +33,7 @@ class StatisticsEventLogFileWriter(private val recorderId: String) : StatisticsE
val dir = getEventLogDir()
fileAppender = StatisticsEventLogFileAppender.create(pattern, dir)
fileAppender?.let { appender ->
appender.setMaxFileSize("200KB")
appender.setMaxFileSize(maxFileSize)
eventLogger.addAppender(appender)
}
}
@@ -8,6 +8,7 @@ import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.text.StringUtil
import java.io.File
import java.util.concurrent.TimeUnit
private val LOG = Logger.getInstance("#com.intellij.internal.statistic.eventLog.StatisticsEventLogger")
private val EP_NAME = ExtensionPointName.create<StatisticsEventLoggerProvider>("com.intellij.statistic.eventLog.eventLoggerProvider")
@@ -19,7 +20,10 @@ interface StatisticsEventLogger {
fun cleanup()
}
abstract class StatisticsEventLoggerProvider(val recorderId: String, val version: Int, val sendFrequencyMs: Long) {
abstract class StatisticsEventLoggerProvider(val recorderId: String,
val version: Int,
val sendFrequencyMs: Long = TimeUnit.HOURS.toMillis(1),
val maxFileSize: String = "200KB") {
open val logger: StatisticsEventLogger = createLogger()
abstract fun isRecordEnabled() : Boolean
@@ -35,8 +39,8 @@ abstract class StatisticsEventLoggerProvider(val recorderId: String, val version
}
val config = EventLogConfiguration
val bucket = config.bucket.toString()
val logger = StatisticsFileEventLogger(config.sessionId, config.build, bucket, version.toString(), StatisticsEventLogFileWriter(recorderId))
val writer = StatisticsEventLogFileWriter(recorderId, maxFileSize)
val logger = StatisticsFileEventLogger(config.sessionId, config.build, config.bucket.toString(), version.toString(), writer)
Disposer.register(ApplicationManager.getApplication(), logger)
return logger
}
@@ -7,7 +7,7 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.util.registry.Registry
import java.util.concurrent.TimeUnit
class FeatureUsageEventLoggerProvider : StatisticsEventLoggerProvider("FUS", 12, TimeUnit.HOURS.toMillis(1)) {
class FeatureUsageEventLoggerProvider : StatisticsEventLoggerProvider("FUS", 12) {
override fun isRecordEnabled(): Boolean {
return !ApplicationManager.getApplication().isUnitTestMode &&
Registry.`is`("feature.usage.event.log.collect.and.upload") &&