From 7699b5fafe7ef196da586cd9868691f4733346b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Mon, 18 Nov 2024 11:59:31 +0100 Subject: [PATCH 1/2] Android native logs --- .../helpers/CustomPushNotificationHelper.java | 36 +-- .../helpers/PushNotificationDataHelper.kt | 8 +- .../rnbeta/CustomPushNotification.kt | 6 +- .../com/mattermost/rnbeta/MainApplication.kt | 7 +- .../rnbeta/NotificationDismissService.java | 4 +- .../NotificationReplyBroadcastReceiver.java | 10 +- .../mattermost/rnbeta/ReceiptDelivery.java | 4 +- ...termost+react-native-turbo-log+0.4.0.patch | 290 ++++++++++++++++++ 8 files changed, 329 insertions(+), 36 deletions(-) create mode 100644 patches/@mattermost+react-native-turbo-log+0.4.0.patch diff --git a/android/app/src/main/java/com/mattermost/helpers/CustomPushNotificationHelper.java b/android/app/src/main/java/com/mattermost/helpers/CustomPushNotificationHelper.java index cbdb968b022..bca394932b0 100644 --- a/android/app/src/main/java/com/mattermost/helpers/CustomPushNotificationHelper.java +++ b/android/app/src/main/java/com/mattermost/helpers/CustomPushNotificationHelper.java @@ -20,7 +20,6 @@ import android.os.Bundle; import android.text.TextUtils; import android.util.Base64; -import android.util.Log; import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; @@ -32,6 +31,7 @@ import com.mattermost.rnbeta.*; import com.mattermost.rnutils.helpers.NotificationHelper; import com.nozbe.watermelondb.WMDatabase; +import com.mattermost.turbolog.TurboLog; import java.io.IOException; import java.security.KeyFactory; @@ -241,36 +241,36 @@ public static void createNotificationChannels(Context context) { public static boolean verifySignature(final Context context, String signature, String serverUrl, String ackId) { if (signature == null) { // Backward compatibility with old push proxies - Log.i("Mattermost Notifications Signature verification", "No signature in the notification"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "No signature in the notification"); return true; } if (serverUrl == null) { - Log.i("Mattermost Notifications Signature verification", "No server_url for server_id"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "No server_url for server_id"); return false; } DatabaseHelper dbHelper = DatabaseHelper.Companion.getInstance(); if (dbHelper == null) { - Log.i("Mattermost Notifications Signature verification", "Cannot access the database"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "Cannot access the database"); return false; } WMDatabase db = getDatabaseForServer(dbHelper, context, serverUrl); if (db == null) { - Log.i("Mattermost Notifications Signature verification", "Cannot access the server database"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "Cannot access the server database"); return false; } if (signature.equals("NO_SIGNATURE")) { String version = queryConfigServerVersion(db); if (version == null) { - Log.i("Mattermost Notifications Signature verification", "No server version"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "No server version"); return false; } if (!version.matches("[0-9]+(\\.[0-9]+)*")) { - Log.i("Mattermost Notifications Signature verification", "Invalid server version"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "Invalid server version"); return false; } @@ -324,7 +324,7 @@ public static boolean verifySignature(final Context context, String signature, S } if (rejected) { - Log.i("Mattermost Notifications Signature verification", "Server version should send signature"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "Server version should send signature"); return false; } @@ -334,7 +334,7 @@ public static boolean verifySignature(final Context context, String signature, S String signingKey = queryConfigSigningKey(db); if (signingKey == null) { - Log.i("Mattermost Notifications Signature verification", "No signing key"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "No signing key"); return false; } @@ -345,17 +345,17 @@ public static boolean verifySignature(final Context context, String signature, S String storedDeviceToken = getDeviceToken(dbHelper); if (storedDeviceToken == null) { - Log.i("Mattermost Notifications Signature verification", "No device token stored"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "No device token stored"); return false; } String[] tokenParts = storedDeviceToken.split(":", 2); if (tokenParts.length != 2) { - Log.i("Mattermost Notifications Signature verification", "Wrong stored device token format"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "Wrong stored device token format"); return false; } String deviceToken = tokenParts[1].substring(0, tokenParts[1].length() -1 ); if (deviceToken.isEmpty()) { - Log.i("Mattermost Notifications Signature verification", "Empty stored device token"); + TurboLog.Companion.i("Mattermost Notifications Signature verification", "Empty stored device token"); return false; } @@ -366,19 +366,19 @@ public static boolean verifySignature(final Context context, String signature, S .build() .parseSignedClaims(signature); } catch (MissingClaimException e) { - Log.i("Mattermost Notifications Signature verification", String.format("Missing claim: %s", e.getMessage())); + TurboLog.Companion.i("Mattermost Notifications Signature verification", String.format("Missing claim: %s", e.getMessage())); e.printStackTrace(); return false; } catch (IncorrectClaimException e) { - Log.i("Mattermost Notifications Signature verification", String.format("Incorrect claim: %s", e.getMessage())); + TurboLog.Companion.i("Mattermost Notifications Signature verification", String.format("Incorrect claim: %s", e.getMessage())); e.printStackTrace(); return false; } catch (JwtException e) { - Log.i("Mattermost Notifications Signature verification", String.format("Cannot verify JWT: %s", e.getMessage())); + TurboLog.Companion.i("Mattermost Notifications Signature verification", String.format("Cannot verify JWT: %s", e.getMessage())); e.printStackTrace(); return false; } catch (Exception e) { - Log.i("Mattermost Notifications Signature verification", String.format("Exception while parsing JWT: %s", e.getMessage())); + TurboLog.Companion.i("Mattermost Notifications Signature verification", String.format("Exception while parsing JWT: %s", e.getMessage())); e.printStackTrace(); return false; } @@ -572,7 +572,7 @@ private static Bitmap userAvatar(final Context context, @NonNull final String se Double lastUpdateAt = 0.0; if (!TextUtils.isEmpty(urlOverride)) { Request request = new Request.Builder().url(urlOverride).build(); - Log.i("ReactNative", String.format("Fetch override profile image %s", urlOverride)); + TurboLog.Companion.i("ReactNative", String.format("Fetch override profile image %s", urlOverride)); response = client.newCall(request).execute(); } else { DatabaseHelper dbHelper = DatabaseHelper.Companion.getInstance(); @@ -594,7 +594,7 @@ private static Bitmap userAvatar(final Context context, @NonNull final String se bitmapCache.removeBitmap(userId, serverUrl); String url = String.format("api/v4/users/%s/image", userId); - Log.i("ReactNative", String.format("Fetch profile image %s", url)); + TurboLog.Companion.i("ReactNative", String.format("Fetch profile image %s", url)); response = Network.getSync(serverUrl, url, null); } diff --git a/android/app/src/main/java/com/mattermost/helpers/PushNotificationDataHelper.kt b/android/app/src/main/java/com/mattermost/helpers/PushNotificationDataHelper.kt index 08a3a3e1c98..437e13072d6 100644 --- a/android/app/src/main/java/com/mattermost/helpers/PushNotificationDataHelper.kt +++ b/android/app/src/main/java/com/mattermost/helpers/PushNotificationDataHelper.kt @@ -2,7 +2,6 @@ package com.mattermost.helpers import android.content.Context import android.os.Bundle -import android.util.Log import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap @@ -15,6 +14,7 @@ import com.mattermost.helpers.push_notification.fetchNeededUsers import com.mattermost.helpers.push_notification.fetchPosts import com.mattermost.helpers.push_notification.fetchTeamIfNeeded import com.mattermost.helpers.push_notification.fetchThread +import com.mattermost.turbolog.TurboLog import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock @@ -50,7 +50,7 @@ class PushNotificationDataRunnable { val isCRTEnabled = initialData.getString("is_crt_enabled") == "true" val ackId = initialData.getString("ack_id") - Log.i("ReactNative", "Start fetching notification data in server=$serverUrl for channel=$channelId and ack=$ackId") + TurboLog.i("ReactNative", "Start fetching notification data in server=$serverUrl for channel=$channelId and ack=$ackId") val receivingThreads = isCRTEnabled && !rootId.isNullOrEmpty() val notificationData = Arguments.createMap() @@ -104,13 +104,13 @@ class PushNotificationDataRunnable { dbHelper.saveToDatabase(db, notificationData, teamId, channelId, receivingThreads) } - Log.i("ReactNative", "Done processing push notification=$serverUrl for channel=$channelId and ack=$ackId") + TurboLog.i("ReactNative", "Done processing push notification=$serverUrl for channel=$channelId and ack=$ackId") } } catch (e: Exception) { e.printStackTrace() } finally { db?.close() - Log.i("ReactNative", "DONE fetching notification data") + TurboLog.i("ReactNative", "DONE fetching notification data") } return result diff --git a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.kt b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.kt index 2c3e1f5db0d..4bd0cf4c1c7 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.kt +++ b/android/app/src/main/java/com/mattermost/rnbeta/CustomPushNotification.kt @@ -3,7 +3,6 @@ package com.mattermost.rnbeta import android.app.PendingIntent import android.content.Context import android.os.Bundle -import android.util.Log import androidx.core.app.NotificationCompat import com.mattermost.helpers.CustomPushNotificationHelper import com.mattermost.helpers.DatabaseHelper @@ -11,6 +10,7 @@ import com.mattermost.helpers.Network import com.mattermost.helpers.PushNotificationDataHelper import com.mattermost.helpers.database_extension.getServerUrlForIdentifier import com.mattermost.rnutils.helpers.NotificationHelper +import com.mattermost.turbolog.TurboLog import com.wix.reactnativenotifications.Defs.NOTIFICATION_RECEIVED_EVENT_NAME import com.wix.reactnativenotifications.core.AppLaunchHelper import com.wix.reactnativenotifications.core.AppLifecycleFacade @@ -84,7 +84,7 @@ class CustomPushNotification( } if (!CustomPushNotificationHelper.verifySignature(mContext, signature, serverUrl, ackId)) { - Log.i("Mattermost Notifications Signature verification", "Notification skipped because we could not verify it.") + TurboLog.i("Mattermost Notifications Signature verification", "Notification skipped because we could not verify it.") return } @@ -104,7 +104,7 @@ class CustomPushNotification( when (type) { CustomPushNotificationHelper.PUSH_TYPE_MESSAGE, CustomPushNotificationHelper.PUSH_TYPE_SESSION -> { val currentActivityName = mAppLifecycleFacade.runningReactContext?.currentActivity?.componentName?.className ?: "" - Log.i("ReactNative", currentActivityName) + TurboLog.i("ReactNative", currentActivityName) if (!mAppLifecycleFacade.isAppVisible() || currentActivityName != "MainActivity") { var createSummary = type == CustomPushNotificationHelper.PUSH_TYPE_MESSAGE if (type == CustomPushNotificationHelper.PUSH_TYPE_MESSAGE) { diff --git a/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.kt b/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.kt index fb323ac4807..bc9fbc82bc4 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.kt +++ b/android/app/src/main/java/com/mattermost/rnbeta/MainApplication.kt @@ -5,7 +5,6 @@ import android.annotation.SuppressLint import android.content.Context import android.content.res.Configuration import android.os.Bundle -import android.util.Log import com.facebook.react.PackageList import com.facebook.react.ReactHost import com.facebook.react.ReactInstanceManager @@ -20,6 +19,8 @@ import com.facebook.react.modules.network.OkHttpClientProvider import com.facebook.soloader.SoLoader import com.mattermost.networkclient.RCTOkHttpClientFactory import com.mattermost.rnshare.helpers.RealPathUtil +import com.mattermost.turbolog.TurboLog +import com.mattermost.turbolog.ConfigureOptions import com.nozbe.watermelondb.jsi.JSIInstaller import com.reactnativenavigation.NavigationApplication import com.wix.reactnativenotifications.RNNotificationsPackage @@ -63,7 +64,9 @@ class MainApplication : NavigationApplication(), INotificationsApplication { // Delete any previous temp files created by the app val tempFolder = File(applicationContext.cacheDir, RealPathUtil.CACHE_DIR_NAME) RealPathUtil.deleteTempFiles(tempFolder) - Log.i("ReactNative", "Cleaning temp cache " + tempFolder.absolutePath) + TurboLog.configure(options = ConfigureOptions(logsDirectory = applicationContext.cacheDir.absolutePath + "/logs", logPrefix = applicationContext.packageName)) + + TurboLog.i("ReactNative", "Cleaning temp cache " + tempFolder.absolutePath) // Tells React Native to use our RCTOkHttpClientFactory which builds an OKHttpClient // with a cookie jar defined in APIClientModule and an interceptor to intercept all diff --git a/android/app/src/main/java/com/mattermost/rnbeta/NotificationDismissService.java b/android/app/src/main/java/com/mattermost/rnbeta/NotificationDismissService.java index 6f72fb5ffc8..e66deb6ae03 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/NotificationDismissService.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/NotificationDismissService.java @@ -4,9 +4,9 @@ import android.content.Intent; import android.app.IntentService; import android.os.Bundle; -import android.util.Log; import com.mattermost.rnutils.helpers.NotificationHelper; +import com.mattermost.turbolog.TurboLog; import com.wix.reactnativenotifications.core.NotificationIntentAdapter; public class NotificationDismissService extends IntentService { @@ -20,6 +20,6 @@ protected void onHandleIntent(Intent intent) { final Bundle bundle = NotificationIntentAdapter.extractPendingNotificationDataFromIntent(intent); NotificationHelper.INSTANCE.dismissNotification(context, bundle); - Log.i("ReactNative", "Dismiss notification"); + TurboLog.Companion.i("ReactNative", "Dismiss notification"); } } diff --git a/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java b/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java index d606b767114..e6afd609ec3 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/NotificationReplyBroadcastReceiver.java @@ -8,7 +8,6 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; -import android.util.Log; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; @@ -18,6 +17,7 @@ import com.facebook.react.bridge.WritableMap; import com.mattermost.helpers.*; +import com.mattermost.turbolog.TurboLog; import com.wix.reactnativenotifications.core.NotificationIntentAdapter; import com.wix.reactnativenotifications.core.notification.PushNotificationProps; @@ -82,22 +82,22 @@ protected void replyToMessage(final String serverUrl, final int notificationId, public void resolve(@Nullable Object value) { if (value != null) { onReplySuccess(notificationId, message); - Log.i("ReactNative", "Reply SUCCESS"); + TurboLog.Companion.i("ReactNative", "Reply SUCCESS"); } else { - Log.i("ReactNative", "Reply FAILED resolved without value"); + TurboLog.Companion.i("ReactNative", "Reply FAILED resolved without value"); onReplyFailed(notificationId); } } @Override public void reject(Throwable reason) { - Log.i("ReactNative", String.format("Reply FAILED exception %s", reason.getMessage())); + TurboLog.Companion.i("ReactNative", String.format("Reply FAILED exception %s", reason.getMessage())); onReplyFailed(notificationId); } @Override public void reject(String code, String message) { - Log.i("ReactNative", + TurboLog.Companion.i("ReactNative", String.format("Reply FAILED status %s BODY %s", code, message) ); onReplyFailed(notificationId); diff --git a/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java b/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java index 9b3c8f0db28..09a5e20f2c1 100644 --- a/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java +++ b/android/app/src/main/java/com/mattermost/rnbeta/ReceiptDelivery.java @@ -1,7 +1,6 @@ package com.mattermost.rnbeta; import android.os.Bundle; -import android.util.Log; import java.lang.System; import java.util.Objects; @@ -12,6 +11,7 @@ import com.facebook.react.bridge.WritableMap; import com.mattermost.helpers.*; +import com.mattermost.turbolog.TurboLog; import okhttp3.Response; @@ -19,7 +19,7 @@ public class ReceiptDelivery { private static final String[] ackKeys = new String[]{"post_id", "root_id", "category", "message", "team_id", "channel_id", "channel_name", "type", "sender_id", "sender_name", "version"}; public static Bundle send(final String ackId, final String serverUrl, final String postId, final String type, final boolean isIdLoaded) { - Log.i("ReactNative", String.format("Send receipt delivery ACK=%s TYPE=%s to URL=%s with ID-LOADED=%s", ackId, type, serverUrl, isIdLoaded)); + TurboLog.Companion.i("ReactNative", String.format("Send receipt delivery ACK=%s TYPE=%s to URL=%s with ID-LOADED=%s", ackId, type, serverUrl, isIdLoaded)); WritableMap options = Arguments.createMap(); WritableMap headers = Arguments.createMap(); WritableMap body = Arguments.createMap(); diff --git a/patches/@mattermost+react-native-turbo-log+0.4.0.patch b/patches/@mattermost+react-native-turbo-log+0.4.0.patch new file mode 100644 index 00000000000..3ca3b4f812a --- /dev/null +++ b/patches/@mattermost+react-native-turbo-log+0.4.0.patch @@ -0,0 +1,290 @@ +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) ++ } ++ } ++} From 95592572309972d281260efa33753b9153026c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Espino=20Garc=C3=ADa?= Date: Tue, 10 Dec 2024 12:55:13 +0100 Subject: [PATCH 2/2] Use latest version of the library --- package-lock.json | 7 +- package.json | 2 +- ...termost+react-native-turbo-log+0.4.0.patch | 290 ------------------ 3 files changed, 5 insertions(+), 294 deletions(-) delete mode 100644 patches/@mattermost+react-native-turbo-log+0.4.0.patch 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) -+ } -+ } -+}