Convert RNLog to Kotlin

Summary:
Convert RNLog to Kotlin

Changelog:
[Internal] [Changed] - Convert RNLog to Kotlin

Reviewed By: mdvacca

Differential Revision: D54010172

fbshipit-source-id: eff124f094248563a2b80575d5ca9e8dae2563f7
This commit is contained in:
Nicola Corti
2024-02-24 01:50:24 -08:00
committed by Facebook GitHub Bot
parent 8bced4b29d
commit 48a723366a
3 changed files with 116 additions and 123 deletions
@@ -5603,20 +5603,20 @@ public abstract interface class com/facebook/react/util/RCTLog : com/facebook/re
public abstract fun logIfNoNativeHook (Ljava/lang/String;Ljava/lang/String;)V
}
public class com/facebook/react/util/RNLog {
public final class com/facebook/react/util/RNLog {
public static final field ADVICE I
public static final field ERROR I
public static final field INSTANCE Lcom/facebook/react/util/RNLog;
public static final field LOG I
public static final field MINIMUM_LEVEL_FOR_UI I
public static final field TRACE I
public static final field WARN I
public fun <init> ()V
public static fun a (Ljava/lang/String;)V
public static fun e (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
public static fun e (Ljava/lang/String;)V
public static fun l (Ljava/lang/String;)V
public static fun t (Ljava/lang/String;)V
public static fun w (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
public static final fun a (Ljava/lang/String;)V
public static final fun e (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
public static final fun e (Ljava/lang/String;)V
public static final fun l (Ljava/lang/String;)V
public static final fun t (Ljava/lang/String;)V
public static final fun w (Lcom/facebook/react/bridge/ReactContext;Ljava/lang/String;)V
}
public class com/facebook/react/viewmanagers/ActivityIndicatorViewManagerDelegate : com/facebook/react/uimanager/BaseViewManagerDelegate {
@@ -1,115 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.util;
import android.util.Log;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.common.ReactConstants;
import javax.annotation.Nullable;
/** Logging wrapper for FLog with LogBox support. */
@Nullsafe(Nullsafe.Mode.LOCAL)
public class RNLog {
public static final int MINIMUM_LEVEL_FOR_UI = Log.WARN;
public static final int LOG = Log.VERBOSE;
public static final int TRACE = Log.DEBUG;
public static final int ADVICE = Log.INFO;
public static final int WARN = Log.WARN;
public static final int ERROR = Log.ERROR;
/**
* Log a log level message tagged as React Native to the console.
*
* @param message The message to log.
*/
public static void l(String message) {
FLog.i(ReactConstants.TAG, message);
}
/**
* Log a trace level message tagged as React Native to the console.
*
* @param message The message to log.
*/
public static void t(String message) {
FLog.i(ReactConstants.TAG, message);
}
/**
* Log a warning level message tagged as React Native to the console. This warning will not be
* shown in LogBox.
*
* @param message The message to log.
*/
public static void a(String message) {
FLog.w(ReactConstants.TAG, "(ADVICE)" + message);
}
/**
* Log a warning level message tagged as React Native to the console and display in the app.
*
* @param context The React context of the application use to display the warning.
* @param message The message to log.
*/
public static void w(@Nullable ReactContext context, String message) {
logInternal(context, message, WARN);
FLog.w(ReactConstants.TAG, message);
}
/**
* Log an error level message tagged as React Native to the console and display in the app.
*
* @param context The React context of the application use to display the error.
* @param message The message to log.
*/
public static void e(@Nullable ReactContext context, String message) {
logInternal(context, message, ERROR);
FLog.e(ReactConstants.TAG, message);
}
/**
* Log an error level message tagged as React Native to the console. This error will not be shown
* in LogBox.
*
* @param message The message to log.
*/
public static void e(String message) {
FLog.e(ReactConstants.TAG, message);
}
private static void logInternal(
@Nullable ReactContext context, @Nullable String message, int level) {
if (level >= MINIMUM_LEVEL_FOR_UI) {
if (context != null && context.hasActiveReactInstance() && message != null) {
context.getJSModule(RCTLog.class).logIfNoNativeHook(levelToString(level), message);
}
}
}
private static String levelToString(int level) {
switch (level) {
case LOG:
case TRACE:
return "log";
case ADVICE:
case WARN:
return "warn";
case ERROR:
return "error";
default:
return "none";
}
}
}
@@ -0,0 +1,108 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.util
import android.util.Log
import com.facebook.common.logging.FLog
import com.facebook.react.bridge.ReactContext
import com.facebook.react.common.ReactConstants
/** Logging wrapper for FLog with LogBox support. */
object RNLog {
const val MINIMUM_LEVEL_FOR_UI = Log.WARN
const val LOG = Log.VERBOSE
const val TRACE = Log.DEBUG
const val ADVICE = Log.INFO
const val WARN = Log.WARN
const val ERROR = Log.ERROR
/**
* Log a log level message tagged as React Native to the console.
*
* @param message The message to log.
*/
@JvmStatic
fun l(message: String) {
FLog.i(ReactConstants.TAG, message)
}
/**
* Log a trace level message tagged as React Native to the console.
*
* @param message The message to log.
*/
@JvmStatic
fun t(message: String) {
FLog.i(ReactConstants.TAG, message)
}
/**
* Log a warning level message tagged as React Native to the console. This warning will not be
* shown in LogBox.
*
* @param message The message to log.
*/
@JvmStatic
fun a(message: String) {
FLog.w(ReactConstants.TAG, "(ADVICE)$message")
}
/**
* Log a warning level message tagged as React Native to the console and display in the app.
*
* @param context The React context of the application use to display the warning.
* @param message The message to log.
*/
@JvmStatic
fun w(context: ReactContext?, message: String) {
logInternal(context, message, WARN)
FLog.w(ReactConstants.TAG, message)
}
/**
* Log an error level message tagged as React Native to the console and display in the app.
*
* @param context The React context of the application use to display the error.
* @param message The message to log.
*/
@JvmStatic
fun e(context: ReactContext?, message: String) {
logInternal(context, message, ERROR)
FLog.e(ReactConstants.TAG, message)
}
/**
* Log an error level message tagged as React Native to the console. This error will not be shown
* in LogBox.
*
* @param message The message to log.
*/
@JvmStatic
fun e(message: String) {
FLog.e(ReactConstants.TAG, message)
}
private fun logInternal(context: ReactContext?, message: String?, level: Int) {
if (level >= MINIMUM_LEVEL_FOR_UI) {
if (context?.hasActiveReactInstance() == true && message != null) {
context.getJSModule(RCTLog::class.java).logIfNoNativeHook(levelToString(level), message)
}
}
}
private fun levelToString(level: Int): String =
when (level) {
LOG,
TRACE -> "log"
ADVICE,
WARN -> "warn"
ERROR -> "error"
else -> "none"
}
}