diff --git a/package-lock.json b/package-lock.json index 7256e058e52..6f57c627297 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "@mattermost/react-native-emm": "1.5.0", "@mattermost/react-native-network-client": "1.7.3", "@mattermost/react-native-paste-input": "0.8.0", - "@mattermost/react-native-turbo-log": "0.4.0", + "@mattermost/react-native-turbo-log": "github:mattermost/react-native-turbo-log#d8ddf5e7974546aff3e83b2c563907eb609ac5f4", "@mattermost/rnshare": "file:./libraries/@mattermost/rnshare", "@mattermost/rnutils": "file:./libraries/@mattermost/rnutils", "@msgpack/msgpack": "2.8.0", @@ -5965,8 +5965,9 @@ }, "node_modules/@mattermost/react-native-turbo-log": { "version": "0.4.0", - "resolved": "https://registry.npmjs.org/@mattermost/react-native-turbo-log/-/react-native-turbo-log-0.4.0.tgz", - "integrity": "sha512-9W0t/FUTyA4mw+RJJ17TXuaPnz/FyBUSDn8poxkdrVjdpeWcIVQCbPOba3BcwDh3owx2JFbp+zGa5PmCHz6Veg==", + "resolved": "git+ssh://git@github.com/mattermost/react-native-turbo-log.git#d8ddf5e7974546aff3e83b2c563907eb609ac5f4", + "integrity": "sha512-ccUGRO2osFTp18ilnKagJa3wHBiaPQtGw2A5Z5+zBsLJTtbdkSQjanjgojgsllhLYj4NCi/VrVXTxks/eLusmw==", + "license": "MIT", "peerDependencies": { "react": "*", "react-native": "*" diff --git a/package.json b/package.json index c8fd07de064..5bfc0bdd725 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@mattermost/react-native-emm": "1.5.0", "@mattermost/react-native-network-client": "1.7.3", "@mattermost/react-native-paste-input": "0.8.0", - "@mattermost/react-native-turbo-log": "0.4.0", + "@mattermost/react-native-turbo-log": "github:mattermost/react-native-turbo-log#d8ddf5e7974546aff3e83b2c563907eb609ac5f4", "@mattermost/rnshare": "file:./libraries/@mattermost/rnshare", "@mattermost/rnutils": "file:./libraries/@mattermost/rnutils", "@msgpack/msgpack": "2.8.0", diff --git a/patches/@mattermost+react-native-turbo-log+0.4.0.patch b/patches/@mattermost+react-native-turbo-log+0.4.0.patch deleted file mode 100644 index 3ca3b4f812a..00000000000 --- a/patches/@mattermost+react-native-turbo-log+0.4.0.patch +++ /dev/null @@ -1,290 +0,0 @@ -index 3f1f4a4..7c205a8 100644 ---- a/node_modules/@mattermost/react-native-turbo-log/android/src/main/java/com/mattermost/turbolog/RNTurboLogModuleImpl.kt -+++ b/node_modules/@mattermost/react-native-turbo-log/android/src/main/java/com/mattermost/turbolog/RNTurboLogModuleImpl.kt -@@ -1,15 +1,5 @@ - package com.mattermost.turbolog - --import android.util.Log --import ch.qos.logback.classic.Level --import ch.qos.logback.classic.LoggerContext --import ch.qos.logback.classic.encoder.PatternLayoutEncoder --import ch.qos.logback.classic.spi.ILoggingEvent --import ch.qos.logback.core.rolling.FixedWindowRollingPolicy --import ch.qos.logback.core.rolling.RollingFileAppender --import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy --import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy --import ch.qos.logback.core.util.FileSize - import com.facebook.react.bridge.Arguments - import com.facebook.react.bridge.Promise - import com.facebook.react.bridge.ReactApplicationContext -@@ -17,10 +7,7 @@ import com.facebook.react.bridge.ReadableArray - import com.facebook.react.bridge.ReadableMap - import com.facebook.react.bridge.ReadableType - import org.json.JSONException --import org.slf4j.Logger --import org.slf4j.LoggerFactory - import java.io.File --import java.nio.charset.StandardCharsets - - class RNTurboLogModuleImpl(reactApplicationContext: ReactApplicationContext) { - private val LOG_LEVEL_DEBUG = 0 -@@ -28,77 +15,12 @@ class RNTurboLogModuleImpl(reactApplicationContext: ReactApplicationContext) { - private val LOG_LEVEL_WARNING = 2 - private val LOG_LEVEL_ERROR = 3 - -- private val logger: Logger = LoggerFactory.getLogger(RNTurboLogModuleImpl::class.java) -- private var logsDirectory: String? = null -- private var configureOptions: ReadableMap? = null -- private val context = reactApplicationContext -- - companion object { - const val NAME = "RNTurboLog" - const val TAG = "TurboLogger" - } - - fun configure(options: ReadableMap?, promise: Promise?) { -- if (options == null) { -- promise?.resolve(Error("Options not defined")) -- return -- } -- val dailyRolling = options.getBoolean("dailyRolling") -- val maximumFileSize = options.getInt("maximumFileSize") -- val maximumNumberOfFiles = options.getInt("maximumNumberOfFiles") -- logsDirectory = if (options.hasKey("logsDirectory") -- ) options.getString("logsDirectory") -- else context.cacheDir.toString() + "/logs" -- val logPrefix = context.packageName -- -- val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext -- -- val rollingFileAppender = RollingFileAppender() -- rollingFileAppender.context = loggerContext -- rollingFileAppender.file = "$logsDirectory/$logPrefix-latest.log" -- -- if (dailyRolling) { -- val rollingPolicy = SizeAndTimeBasedRollingPolicy() -- rollingPolicy.context = loggerContext -- rollingPolicy.fileNamePattern = "$logsDirectory/$logPrefix-%d{yyyy-MM-dd}.%i.log" -- rollingPolicy.setMaxFileSize(FileSize(maximumFileSize.toLong())) -- rollingPolicy.setTotalSizeCap(FileSize(maximumNumberOfFiles.toLong() * maximumFileSize)) -- rollingPolicy.maxHistory = maximumNumberOfFiles -- rollingPolicy.setParent(rollingFileAppender) -- rollingPolicy.start() -- rollingFileAppender.setRollingPolicy(rollingPolicy) -- } else if (maximumFileSize > 0) { -- val rollingPolicy = FixedWindowRollingPolicy() -- rollingPolicy.context = loggerContext -- rollingPolicy.fileNamePattern = "$logsDirectory/$logPrefix-%i.log" -- rollingPolicy.minIndex = 1 -- rollingPolicy.maxIndex = maximumNumberOfFiles -- rollingPolicy.setParent(rollingFileAppender) -- rollingPolicy.start() -- rollingFileAppender.rollingPolicy = rollingPolicy -- -- val triggeringPolicy = SizeBasedTriggeringPolicy() -- triggeringPolicy.context = loggerContext -- triggeringPolicy.maxFileSize = FileSize(maximumFileSize.toLong()) -- triggeringPolicy.start() -- rollingFileAppender.setTriggeringPolicy(triggeringPolicy) -- } -- -- val encoder = PatternLayoutEncoder() -- encoder.context = loggerContext -- encoder.charset = StandardCharsets.UTF_8 -- encoder.pattern = "%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level %msg%n" -- encoder.start() -- -- rollingFileAppender.encoder = encoder -- rollingFileAppender.start() -- -- val root = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger -- root.level = Level.DEBUG -- root.detachAndStopAllAppenders() -- root.addAppender(rollingFileAppender) -- -- configureOptions = options - promise?.resolve(null) - } - -@@ -106,23 +28,19 @@ class RNTurboLogModuleImpl(reactApplicationContext: ReactApplicationContext) { - val str: String = format(messages) - when (level) { - LOG_LEVEL_DEBUG -> { -- logger.debug(str) -- Log.d(TAG, str) -+ TurboLog.d(TAG, str) - } - - LOG_LEVEL_INFO -> { -- logger.info(str) -- Log.i(TAG, str) -+ TurboLog.i(TAG, str) - } - - LOG_LEVEL_WARNING -> { -- logger.warn(str) -- Log.w(TAG, str) -+ TurboLog.w(TAG, str) - } - - LOG_LEVEL_ERROR -> { -- logger.error(str) -- Log.e(TAG, str) -+ TurboLog.e(TAG, str) - } - } - } -@@ -144,19 +62,14 @@ class RNTurboLogModuleImpl(reactApplicationContext: ReactApplicationContext) { - for (file in getLogFiles()) { - file.delete() - } -- if (configureOptions != null) { -- configure(configureOptions, promise) -- } else { -- promise?.resolve(true) -- } -+ TurboLog.reconfigure() - } catch (e: java.lang.Exception) { - promise?.resolve(false) - } - } - - private fun getLogFiles(): Array { -- val directory = logsDirectory?.let { File(it) } -- return directory?.listFiles { _, name -> name.endsWith(".log") } ?: arrayOf() -+ return TurboLog.getLogFiles() - } - - private fun format(messages: ReadableArray?): String { -diff --git a/node_modules/@mattermost/react-native-turbo-log/android/src/main/java/com/mattermost/turbolog/TurboLog.kt b/node_modules/@mattermost/react-native-turbo-log/android/src/main/java/com/mattermost/turbolog/TurboLog.kt -new file mode 100644 -index 0000000..9735c0a ---- /dev/null -+++ b/node_modules/@mattermost/react-native-turbo-log/android/src/main/java/com/mattermost/turbolog/TurboLog.kt -@@ -0,0 +1,126 @@ -+package com.mattermost.turbolog -+ -+import android.util.Log -+import ch.qos.logback.classic.Level -+import ch.qos.logback.classic.LoggerContext -+import ch.qos.logback.classic.encoder.PatternLayoutEncoder -+import ch.qos.logback.classic.spi.ILoggingEvent -+import ch.qos.logback.core.rolling.FixedWindowRollingPolicy -+import ch.qos.logback.core.rolling.RollingFileAppender -+import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy -+import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy -+import ch.qos.logback.core.util.FileSize -+import org.slf4j.Logger -+import org.slf4j.LoggerFactory -+import java.io.File -+import java.nio.charset.StandardCharsets -+ -+data class ConfigureOptions( -+ val dailyRolling: Boolean? = null, -+ val logsDirectory: String? = null, -+ val maximumFileSize: Int? = null, -+ val maximumNumberOfFiles: Int? = null, -+ val logPrefix: String? = null, -+) -+ -+class TurboLog { -+ companion object { -+ private val logger: Logger = LoggerFactory.getLogger(TurboLog::class.java) -+ private var logsDirectory: String? = null -+ private var configureOptions: ConfigureOptions? = null -+ -+ fun getLogFiles(): Array { -+ val directory = logsDirectory?.let { File(it) } -+ return directory?.listFiles { _, name -> name.endsWith(".log") } ?: arrayOf() -+ } -+ -+ fun reconfigure() { -+ configureOptions?.let { configure(it) } -+ } -+ -+ fun configure(options: ConfigureOptions) { -+ val dailyRolling = options.dailyRolling ?: false -+ val maximumFileSize = options.maximumFileSize ?: (1024 * 1024) -+ val maximumNumberOfFiles = options.maximumNumberOfFiles ?: 2 -+ logsDirectory = options.logsDirectory ?: "" -+ val logPrefix = options.logPrefix ?: "" -+ -+ val loggerContext = LoggerFactory.getILoggerFactory() as LoggerContext -+ -+ val rollingFileAppender = RollingFileAppender() -+ rollingFileAppender.context = loggerContext -+ rollingFileAppender.file = "$logsDirectory/$logPrefix-latest.log" -+ -+ if (dailyRolling) { -+ val rollingPolicy = SizeAndTimeBasedRollingPolicy() -+ rollingPolicy.context = loggerContext -+ rollingPolicy.fileNamePattern = "$logsDirectory/$logPrefix-%d{yyyy-MM-dd}.%i.log" -+ rollingPolicy.setMaxFileSize(FileSize(maximumFileSize.toLong())) -+ rollingPolicy.setTotalSizeCap(FileSize(maximumNumberOfFiles.toLong() * maximumFileSize)) -+ rollingPolicy.maxHistory = maximumNumberOfFiles -+ rollingPolicy.setParent(rollingFileAppender) -+ rollingPolicy.start() -+ rollingFileAppender.setRollingPolicy(rollingPolicy) -+ } else if (maximumFileSize > 0) { -+ val rollingPolicy = FixedWindowRollingPolicy() -+ rollingPolicy.context = loggerContext -+ rollingPolicy.fileNamePattern = "$logsDirectory/$logPrefix-%i.log" -+ rollingPolicy.minIndex = 1 -+ rollingPolicy.maxIndex = maximumNumberOfFiles -+ rollingPolicy.setParent(rollingFileAppender) -+ rollingPolicy.start() -+ rollingFileAppender.rollingPolicy = rollingPolicy -+ -+ val triggeringPolicy = SizeBasedTriggeringPolicy() -+ triggeringPolicy.context = loggerContext -+ triggeringPolicy.maxFileSize = FileSize(maximumFileSize.toLong()) -+ triggeringPolicy.start() -+ rollingFileAppender.setTriggeringPolicy(triggeringPolicy) -+ } -+ -+ val encoder = PatternLayoutEncoder() -+ encoder.context = loggerContext -+ encoder.charset = StandardCharsets.UTF_8 -+ encoder.pattern = "%d{yyyy/MM/dd HH:mm:ss.SSS} %-5level %msg%n" -+ encoder.start() -+ -+ rollingFileAppender.encoder = encoder -+ rollingFileAppender.start() -+ -+ val root = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger -+ root.level = Level.DEBUG -+ root.detachAndStopAllAppenders() -+ root.addAppender(rollingFileAppender) -+ -+ configureOptions = options -+ } -+ -+ fun d(tag: String, message: String) { -+ if (configureOptions != null) { -+ logger.debug("$tag: $message") -+ } -+ Log.d(tag, message) -+ } -+ -+ fun e(tag: String, message: String) { -+ if (configureOptions != null) { -+ logger.error("$tag: $message") -+ } -+ Log.e(tag, message) -+ } -+ -+ fun i(tag: String, message: String) { -+ if (configureOptions != null) { -+ logger.info("$tag: $message") -+ } -+ Log.i(tag, message) -+ } -+ -+ fun w(tag: String, message: String) { -+ if (configureOptions != null) { -+ logger.warn("$tag: $message") -+ } -+ Log.w(tag, message) -+ } -+ } -+}